php – Escaping & in GET-ThrowExceptions

Exception or error:

I have this link:

http://localhost/dow.php?url=/site.net/page.php?action=download&id=3424&authkey=234234324242342

and

$_GET["url"]

should be

=/site.net/page.php?action=download&id=3424&authkey=234234324242342` 

but when i try

print $_GET["url"]; 

it only prints /site.net/page.php?action=download

The problem it’s obviously with & char, i tried htmlspecialchars($_GET["url"]) with no luck.
What can i do to have the entire string?

How to solve:

I don’t know where did you get the target url, but try encode it before you print it in the get.
i.e encodeURIComponent function in JS, rawurlencode in PHP, or just use this ref here to replace any html chars you want. And rawurldecode it after $_GET['url'].

Answer:

To get the full request you’ll have to use $_SERVER['QUERY_STRING'];

eg :

echo $_SERVER['QUERY_STRING'];

Answer:

Nope that is because the other two params are different.

You need to get each of them separately. like $_GET['id'], $_GET['authkey']

or you could just make use of a foreach construct.

foreach($_GET as $k=>$v)
{
 $myparams[$k]=$v;
}

echo $myparams['authkey'];// "prints" 234234324242342

Leave a Reply

Your email address will not be published. Required fields are marked *