views:

182

answers:

4

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?

+2  A: 

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.

Gumbo
+1 for beating me by 1 minute
St. John Johnson
A: 

It looks like you are not using the query string "correctly." It should be in key=value pairs. I would look at using $_SERVER['QUERY_STRING'] to get your information instead.

St. John Johnson
i tried to print like echo $_SERVER['alias']; but not printing anything
pradeep
No no, QUERY_STRING is a keyword that defines the information after the ? in your URL. This would equal "alias=F%26B"
St. John Johnson
hey i have few things to explain over here . basically i have .htaccess entry like[CODE] RewriteRule ^Restaurants/(.*)$ /restaurant_rating.php?alias=$1 [L][/CODE]so i pass like [CODE]http://abc.com/Restaurants/F%26B [/CODE]which gets converted to [CODE]http://abc.com/restaurant_rating.php?alias=F%26B[/CODE]internally .so when i tried directly to use [CODE]http://abc.com/restaurant_rating.php?alias=F%26B[/CODE]and print alias . it prints properly but when i use [CODE]http://abc.com/Restaurants/F%26B [/CODE]and print alias it prints only F .how to solve this problem ?
pradeep
Hmm. Sounds like the RegEX for your Rewrite Rule isn't working. This might be better as a separate question.
St. John Johnson
Wait, I think I know what is happening! What is the output of $_SERVER['QUERY_STRING'].
St. John Johnson
pradeep
A: 

You don't need to urlencode the pair. You only need to urlencode name and a value as such:

Wrong:

urlencode('aliasF=B')

Correct:

urlencode('aliasF') . '=' . urlencode('B')
Daniil
pradeep
A: 

AFAIK $_GET are already decoded.

See php.net

The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.

Shuriken