2014-11-25 53 views
-1

我正在使用php脚本重定向我的网站中的用户,它一直工作得很好,直到上个星期一,突然它可以正常工作,有时它重定向到另一个实例上的期望页面错误。为什么我的重定向工作是随机的

重定向URL

devaltrack.dailyusers.com/rd?track=130&go=www.bbc.co.uk 

自带有时

请求的URL /www.bbc.co.uk错误在此服务器上找到。

当我深入挖掘它,我意识到,如果我键入go值与http,它会永远工作,没有它工作时有时无, 有谁能够给我什么怎么回事

一个可能的线索

重定向脚本

$redirect_page= '/rccp.php'; 
$trusted_domain = $_GET['go']; 
$track_id = $_GET['track']; 

    $strsql = ("CALL select_whitelisturls($track_id)"); 
    $result = mysql_query($strsql); 
    $row = mysql_fetch_array($result); 

if($row==""){ 
    redirect_cookie_user($redirect_page); 
} 

if($row["redirect"] == 1){ 

    if (false === strpos($trusted_domain, '://')) { 
     $trusted_domain = 'http://' . $trusted_domain; 
     //$trusted_domain = strtolower($trusted_domain); 
    } 

    if ($i = strpos($trusted_domain, '/', strpos($trusted_domain, '//')+2)){ 
     $trusted_domain = strtolower(substr($trusted_domain, 0, $i)). substr($trusted_domain, $i); 
    }else{ 
     $trusted_domain = strtolower($trusted_domain); 
    } 

    $domainarray = explode("\n", $row['domainname']); 
    if ($domainarray[0] == null){ 
     exit(); 
    } 

    foreach ($domainarray as $value) { 
     if (false === strpos($value , '://')) { 
      $value = "http://".$value; 
      $value = strtolower($value);  
     }else 
     { 
      $value = strtolower($value); 
     } 
     $pos = strrpos($trusted_domain, $value); 
     $domain_string =parse_url($trusted_domain); 
     $value_string =parse_url($value); 

     if(($pos !== false) &&($pos == 0) && ($value_string['host'] == $domain_string['host'])){ 
      if (isset($_COOKIE["id"])){ 
       $_GET['id'] = $_COOKIE["id"]; 
       $_GET['go'] = $trusted_domain; 
       header('Location: '.$redirect_page.'?'.http_build_query($_GET)); 
       exit(); 
      }else{ 
       header('Location: '.$trusted_domain); 
       exit(); 
      } 
     } 
    } 
}else{ 
    exit(); 
} 
function redirect_cookie_user($redirect_page){ 
    if (isset($_COOKIE["id"])){ 
     $_GET['id'] = $_COOKIE["id"]; 
     header('Location: '.$redirect_page.'?'.http_build_query($_GET)); 
    } 
    else{ 
     exit(); 
    } 
} 
+0

它被解释为本地URL路径,而不是URL,除非你写了一个包含协议前缀。 – mario 2014-11-25 08:01:18

+0

如果你需要实现的帮助(假如它真的在你声称的之前工作),你将不得不显示上述代码。 – mario 2014-11-25 08:02:25

+0

对不起,我的本地跟踪网址..等不及格编辑它.. – 2014-11-25 08:02:54

回答

1

我认为你的问题是打印重定向代码。如果您使用标题('Location:xxxx');那么xxxx应该始终具有模式(http,https等),否则浏览器会尝试相对导航。

编辑: 你可以这样做:

// For testing 
$go = 'www.bbc.co.uk';                                                        
//$go = 'http://www.bbc.co.uk';                                                      

$uriInfo = parse_url($go);                                                     

if (!isset($uriInfo['scheme'])) {                                                    
    $go = 'http://' . $go;                                                      
} 

header('Location: ' . $go) 

现在,如果该模式被定义,你会检查,如果没有,你会追加的“http://”

+0

等待虐待添加代码..可以üchk任何瑕疵 – 2014-11-25 08:04:42

+0

据我所知,在我的代码没有瑕疵是没有它,我想我已经在上面这样做了,btw可以ü请你chk我的代码上面..谢谢 – 2014-11-25 08:10:42

+0

@ user3584871我还没有看到你在代码中的错误...我唯一看到的是,如果去'bbc.com://',它会失败,因为你只是检查': //'在字符串中。你可能会像我做这个例子时那样做检查。 – goddva 2014-11-25 08:24:11

0

,如果你不使用“http://”它会搜索您的网站空间(不存在)上的“www.bbc.co.uk”文件夹。你应该在url之前加上一个“//”(让浏览器决定他是否想要https或http)

+0

将代码添加到了帖子中 – 2014-11-25 08:09:15

相关问题