重定向脚本

时间:2013-11-19 01:20:40

标签: php redirect

我正在尝试编写一个用于跟踪的PHP脚本...

if country = in or ca
redirect_to http://example.com
else redirect to http://example2.com

if $_GET['foo'] = 'bar' and country = in or ca
redirect to http://example3.com

else redirect to example.com
else redirect to example.com

我试过跟......

$country = $_SESSION['countrycode'];

//if country india,canada
if($country == 'in' || $country == 'ca') redirect_to('http://example.com/');
else redirect_to('http://example2.com/');

//if querysting contains foo=bar and country india,canada
if($_GET['foo'] == 'bar'){
    if($country == 'in' || $country == 'ca') redirect_to('http://example3.com/');
    else redirect_to('http://example.com/');
}
else redirect_to('http://example.com/');

但是在查询字符串foo = bar的情况下它不起作用。请建议。

1 个答案:

答案 0 :(得分:2)

您的第一个条件语句是将页面重定向到此脚本之外。永远不会读取第二个条件语句。相反,你应该重构这样的东西:

if($country == 'in' || $country == 'ca'){
    if($_GET['foo'] === 'bar')
        header('Location: ' . $urlof3);
    else
        header('Location: '. $urlof2);
}

干杯