【问题标题】:Redirecting My site from two domain's tlds causing a infinte redirect loop从两个域 tld 重定向我的站点导致无限重定向循环
【发布时间】:2016-08-09 06:25:56
【问题描述】:

我有一个名为 smarkmart 的网站。我想以三种方式重定向它。 1. 在印度,它应该在 www.smarkmart.in 2. 在美国它应该在 www.smarkmart.com 3. 其他的应该在 www.smarkmart.com 上

这是我的重定向代码-

session_start();
require 'geoplugin.class.php';
$geoplugin = new geoPlugin();
$geoplugin->locate();
if (isset($_SESSION['pricetype'])) {
    unset($_SESSION['pricetype']);
}
// create a variable for the country code
$var_country_code = $geoplugin->countryCode;
// redirect based on country code:
if (!isset($_SESSION['pricetype'])) {
    if ($var_country_code == "US") {
        header('Location: http://www.smarkmart.com');
        $_SESSION['pricetype'] = "priceinr";
    }
    if ($var_country_code == "IN") {
        header('Location: http://www.smarkmart.in');
        $_SESSION['pricetype'] = "priceusd";
    } else {
        header('Location: http://www.smarkmart.com');
        $_SESSION['pricetype'] = "priceinr";
    }
}
$pricetype = $_SESSION['pricetype'];

这会导致无限循环。任何帮助,将不胜感激。提前致谢。

【问题讨论】:

标签: php session redirect


【解决方案1】:

仅当 $_SESSION['pricetype'] 为 null 但您在脚本开头取消设置时才重定向:

if(isset($_SESSION['pricetype']))
{
    unset($_SESSION['pricetype']);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2021-05-08
    • 2015-11-09
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多