Jump to content

encoding url not working


andy1212

Recommended Posts

I'm trying to encode a url like this,

$code = '2';

header('Location: http://www.whatever.com/page.php?='.urlencode($code).'');
exit();

and then decoding it on the page.php page like this,

$url = $_SERVER['REQUEST_URI'];
$decodedurl = urldecode($url);

$code = $_GET[$decodedurl];

echo $code;

But when the header redirects to page.php, "2" doesn't get encoded, it just says "page.php?code=2"

 

How can I get this to work? Thanks for your time.

Link to comment
https://forums.phpfreaks.com/topic/280783-encoding-url-not-working/
Share on other sites

The number 2 does not need to be encoded. Only special characters / high-order characters need to be encoded. Also there is no need to decode the URL. PHP does that automatically when it parses the variables out. So on your receiving page you'd just do $_GET['code'] like normal.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.