2012-05-27 16 views

回答

1

您可以發送一個HTTP報頭重定向到另一個頁面:

header("Location: foo.php"); 

...或一個完整的URL:

header("Location: http://www.google.co.uk/"); 

注意,你應該在任何其他輸出(即回聲)之前發送標頭。

0

,如果你想測試一個「特殊」的網址,你需要先構建它:

$ssl = ""; 
if ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on") || (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"]=="443")) 
    { $ssl = "s"; } 

$serverport = ($_SERVER["SERVER_PORT"]!="80"?":".$_SERVER["SERVER_PORT"]:""); 

$theurl = "http".$ssl."://".$_SERVER["SERVER_NAME"].$serverport.$_SERVER["REQUEST_URI"]; 

然後,你可以測試它反對另一個URL(或它們的陣列):

if ($theurl != $myurl) { 
    header("Location: index.php"); 
} 

對網址的數組:

if (in_array($theurl,$myurls)) { 
    header("Location: index.php"); 
} 
相關問題