开发者

Compare string with basename

I want to find out if the end of the URL is, for example, ?vote

Using basename($_SERVER['REQUEST_URI']).PHP_EOL, I thought I could compare this with a string of '?vote' , but its not working.

 $url = basename($_SERVER['REQUEST_URI']).PHP_EOL;
 if (strcasecmp($url, "?vote")开发者_运维技巧 == 0)
  {
    echo "they match";
  }
  else
  {
    echo "they DO NOT match";
  }


How about

if ($_SERVER['QUERY_STRING'] == 'vote')
{
    echo "they match";
}
else
{
    echo "they DO NOT match";
}


The access to your ?vote, we call it a Query String, and with PHP you can access to it like this $_SERVER['QUERY_STRING']. So you don't need to use basename.


    if(isset($_GET['vote']))
...........................


To figure out if the vote query parameter is set, use:

isset($_GET['vote'])

If you really care about the position of the parameter coming right after ? (you should't), match the value against $_SERVER['QUERY_STRING']. How exactly depends on whether vote should have a value or not and whether other parameters should be allowed or not. URLs are defined so the order of parameters in the query really shouldn't make any difference to you though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜