我試圖使用GET url中的查詢來確定頁面的內容。 這是我(編輯爲清楚起見句子):比較PHP中的URL字符串
<?php
//decalre variables
$title ='';
$welcome = '';
$params = '';
$params = $_SERVER['QUERY_STRING'];
echo $_SERVER['QUERY_STRING'];
echo $params;
if ($params='') {
header('start.html') ;
} else {
if ($params === "selection=republic") {
//echo $params;
//echo 'Republic';
$title = "Private";
$welcome = "Our .";
$signoff = "The Republic will strike back!";
}
else if ($params === "selection=rebels") {
//echo $params;
//echo 'Rebels';
$title = "Comrade";
$welcome = "Hey comrade, welcome to the Underground Network!";
$declaration="You see,o's!";
$signoff = "Rebel!!";
}
else if ($params === "selection=robots"){
//echo $params;
//echo 'Robots';
$title = "Bit";
$welcome = "Our data ";
$declaration="Knowledge w.";
$signoff = "ed now.";
}
else {
echo 'There was an error - please go back.';
}
}
第一回波顯示正確的URL,但比較卡在第三個選項。 幫助!
我相信第一個'如果($ PARAMS = '')'應該是'=='。 – wroniasty
爲什麼不使用'$ _GET ['selection']'? –
if((空($變量))而不是if($ variable =='')...用於檢測是否沒有值或空白((和0也是如此注意整數))更好。 – aleation