2014-11-25 49 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

相關問題