希望有人可以幫助我與此。我試圖包含一個基於國家和移動與否的文件。PHP如果和 - 國家/移動或不移動包括
這裏是我使用的檢查,如果該設備是移動還是不是代碼:
$_SERVER['HTTP_USER_AGENT'];
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
if ($iphone || $android || $palmpre || $ipod || $ipad || $berry == true)
{
include("mobile.php");
}
else {
include("desktop.php");
}
這裏是我使用的檢查位置和重定向代碼:
require_once('geo/geoip.inc');
$gi = geoip_open('geo/GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
if ($country == 'FR') {
header('Location: fr.php');
}
elseif ($country == 'BE') {
header('Location: be.php');
}
elseif ($country == 'CA') {
header('Location: ca.php');
}
elseif ($country == 'CH') {
header('Location: ch.php');
}
else {
}
我想包括,而不是重定向。所以,如果移動和位置是FR,我會包括(「mobilefr.php」); - 不移動將包括desktopfr。其他國家也一樣,默認(或沒有列出國家)將mobile.php和desktop.php
我試過自己做,但不斷卡住/錯誤。
在此先感謝。
注意:你的'==真'是關係到'$ berry'只和完全多餘 –