Search code examples
phpurlurl-encoding

Passing & in URL variable with the help of urlencode


I have done urlencode of the variable before passing to the URL

http://example.com/Restaurants?alias=F%26B

But when I try to print like in the page

 $alias =  rawurldecode($_GET['alias']);
 echo $alias;

it prints only F. How to solve this?


Solution

  • I doubt that $_GET['alias'] exists when requesting a URL with the query aliasF%26B. It’s rather $_GET['aliasF&B'] that’s getting populated.

    In this case you need to use $_SERVER['QUERY_STRING'] to get the full query.