我正在开发一个自定义的contentlocker,在这里我显示基于移动/桌面平台、操作系统和用户所在国家/地区的内容。
我被困在了我想展示内容的部分。如果来自美国的用户进入我的网站,它需要显示具有不同内容的网页,那么来自CA的用户应该看到。
现在我们进入php脚本的部分,脚本确定这是一个来自美国的用户,它将向我们显示网页,以及美国的内容。但是不更改当前打开的url。(因此没有重定向/标头位置:"URL");)
它需要在同一页上显示确定的内容。
我该怎么做?
我可以回显php文件中的内容吗?我可以使用readfile吗?
我有点迷失了方向,它仍然需要执行页面中的脚本,就像你通过url访问页面一样。
您只需动态创建include:
if ($inUS) {
$include = 'us_users.php';
} else {
$include = 'outside_us_users.php';
}
include($include);
对于更多的国家,只需使用切换语句:
switch($country) {
case "DE":
$include = "de_users.php";
beak;
case "MX":
$include = "mx_users.php";
break;
case "US": // US falls through to default
default:
$include = "us_users.php";
break;
}
include($include);
在页面的开头设置:
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
case "fr":
include('translate/index_fr.php');
break;
default:
include('translate/index_en.php');
break;
}
echo $lg['test1'] . $lg['test2'];
英文文件:(index_en.php
)
<?php
$lg = array(
'test' => 'Hello',
'test2' => 'World'
);
?>
FR文件(index_fr.php
)
<?php
$lg = array(
'test' => 'Bonjour',
'test2' => 'la terre'
);
?>