根据访问者所在的国家/地区更改目标 link
Change target link based on visitor's country
我有网站。com/sample-page 有一些文字和一个下载按钮(外部 link 喜欢下载。com/file)
如果用户来自法国,我想更改目标 link(下载。com/file)。我不想重定向整个 page/website,只重定向这个 link.
我正在使用 wordpress(如果有帮助的话)。
请多多指教。
非常简单,你需要检测用户语言,然后使用 if、elseif、else 并在需要时调用 header 位置或简单地执行 link 的 echo...
$find = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($find,0,2);
if ($lang == "fr") {
header("Location: download.com/file_fr");
exit();
} elseif ($lang == "it") {
header("Location: download.com/file_it");
exit();
} elseif ($lang == "xx") {
header("Location: download.com/file_xx");
exit();
} else {
header("Location: download.com/file");
exit();
}
或使用其他技巧...
$link = "";
$find = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($find,0,2);
if ($lang == "fr") {
$link = "download.com/file_fr";
} elseif ($lang == "it") {
$link = "download.com/file_it";
} elseif ($lang == "xx") {
$link = "download.com/file_xx";
} else {
$link = "download.com/file";
}
echo "<a href=\"$link\" target=\"_blank\">$link</a>";
如果我的回答是您想要的,请告诉我:)
我有网站。com/sample-page 有一些文字和一个下载按钮(外部 link 喜欢下载。com/file)
如果用户来自法国,我想更改目标 link(下载。com/file)。我不想重定向整个 page/website,只重定向这个 link.
我正在使用 wordpress(如果有帮助的话)。 请多多指教。
非常简单,你需要检测用户语言,然后使用 if、elseif、else 并在需要时调用 header 位置或简单地执行 link 的 echo...
$find = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($find,0,2);
if ($lang == "fr") {
header("Location: download.com/file_fr");
exit();
} elseif ($lang == "it") {
header("Location: download.com/file_it");
exit();
} elseif ($lang == "xx") {
header("Location: download.com/file_xx");
exit();
} else {
header("Location: download.com/file");
exit();
}
或使用其他技巧...
$link = "";
$find = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($find,0,2);
if ($lang == "fr") {
$link = "download.com/file_fr";
} elseif ($lang == "it") {
$link = "download.com/file_it";
} elseif ($lang == "xx") {
$link = "download.com/file_xx";
} else {
$link = "download.com/file";
}
echo "<a href=\"$link\" target=\"_blank\">$link</a>";
如果我的回答是您想要的,请告诉我:)