2016-10-13 131 views
1

我有一个URL查询在get.php?&uniId=2我有代码检查是否存在url字符串。检查URLquery是否匹配

但是我的if语句似乎剂量不正确地工作

<?php 

if(empty($_GET {"uniId=3"})) { 
    echo "you are able to accsess this page !"; 

    var_dump($_REQUEST); 

} else { 
    echo "sorry no access for you"; 
} 

,如果我在http://localhost/mysite/get.php?&uniId=3

型我得到

echo "you are able to accsess this page !"; 

,如果我在http://localhost/mysite/get.php?&uniId=2

型我得到

echo "you are able to accsess this page !";

echo "sorry no access for you"; 

回答

1

只是检查关键第一,比存在,检查值:

即:

//check if the key exists 
if(!empty($_GET{"uniId"})) { 
    // check if the value = 3 
    if ($_GET{"uniId"} == 3) { 
     // do stuff if result is true 
    } else { 
     // do stuff if result is false 
    } 
} else { 
    echo "The key \"uniId\" does not exists"; 
} 

希望它能帮助。

+0

完美,谢谢。很高兴看到我接近 –

+0

很高兴它可以帮助你。请点击投票柜台下面的绿色抽屉,如果这个答案解决了你的问题。 – JazZ

+1

已经完成了,刚刚等了10分钟 –

相关问题