BorisD
BorisD

Reputation: 1814

Introducing a PHP variable into a Header redirect

this is my code:

header("Location: ?pid='".$_GET['pid']."'");
die();

When I write a simple echo $_GET['pid']; the value is good but then when I introduce this variable in the header it return something like 27%27 and thats not true true value

When I use urlencode the probleme persist:

header("Location: ?pid=". urlencode($_GET['pid']);

Whats the problem here?

Thank you

Upvotes: 1

Views: 411

Answers (1)

divix
divix

Reputation: 1364

This is because the parameter is being encoded into URL format. Read about urldecode() PHP function.

Also, the %27 is a URL encoded single quote char, therefore you need to remove single quotes from your code:

header("Location: ?pid=".$_GET['pid']);

If you still however will get %27 in your header, then I would suggest stripping it out from var by using trim() like this:

header("Location: ?pid=".trim($_GET['pid'], "'"));

Upvotes: 2

Related Questions