andy1212 Posted August 3, 2013 Share Posted August 3, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280783-encoding-url-not-working/ Share on other sites More sharing options...
andy1212 Posted August 3, 2013 Author Share Posted August 3, 2013 so in the url bar of the browser window it shows, http://www.whatever.com/page.php?code=2 but I thought it would show something like, page.php?code=%&2&% Quote Link to comment https://forums.phpfreaks.com/topic/280783-encoding-url-not-working/#findComment-1443296 Share on other sites More sharing options...
Solution kicken Posted August 3, 2013 Solution Share Posted August 3, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280783-encoding-url-not-working/#findComment-1443298 Share on other sites More sharing options...
andy1212 Posted August 3, 2013 Author Share Posted August 3, 2013 ok thanks! Quote Link to comment https://forums.phpfreaks.com/topic/280783-encoding-url-not-working/#findComment-1443301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.