我正在尝试将网络中的用户重定向到我们网站上的特定目标网页,具体取决于他们的IP和空白推荐人。此代码有效,但最终会出现重定向循环。如何突破重定向循环以正确重定向用户?谢谢!
$visitor = $_SERVER['HTTP_REFERER'];
$clientip = $_SERVER['REMOTE_ADDR'];
$ip = a regex list of IPs;
if (empty($visitor))
{
if (preg_match($ip, $clientip)) {
header('Location: http://example.com');
die();
}
}
答案 0 :(得分:3)
向该用户添加一个您知道它们已被重定向的会话:
session_start();
$visitor = $_SERVER['HTTP_REFERER'];
$clientip = $_SERVER['REMOTE_ADDR'];
$ip = a regex list of IPs;
if (empty($visitor))
{
//add on if they did not redirect yet.
if (preg_match($ip, $clientip) &&
(!isset($_SESSION['redirect']) || !$_SESSION['redirect'])) {
$_SESSION['redirect'] = true;
header('Location: http://example.com');
die();
}
}