2013-04-09 38 views
0

我需要能夠獲得文件名和「頁面」變量在一個字符串或其他東西。因爲我需要檢查你是否來自index.php或其他頁面。我的代碼的問題是,語句將始終爲「真」,因爲「$ file」只包含文件名,而不包含文件名和$ _GET變量例如(index.php?page = news)。任何想法傢伙?頁面選擇器PHP

$file = mysql_real_escape_string(basename(__FILE__)); 

if ($file != "index.php") 
    $page = mysql_real_escape_string($_GET['page']); 

else 
    $page = "index"; 

回答

0

檢查!empty($_GET["page"])而不是$file != "index.php"。如果在參數page中還有內容,則只設置$page

+0

THX,它的工作! :d – 2013-04-09 20:24:39

0

您需要將Querystring添加到$ file var的末尾以進行比較。 $ _GET包含了查詢字符串,並http_build_query()會把它變成一個KVP格式,如 「VAR1 = VAL1 & VAR2 = VAL2 & VAR3 = VAL3」:

 
$file = mysql_real_escape_string(basename(__FILE__)) .http_build_query($_GET); 

if ($file != "index.php") 
    $page = mysql_real_escape_string($_GET['page']); 

else 
    $page = "index";