DLO2418 Posted June 22, 2014 Share Posted June 22, 2014 I am using rawurlencode for my urls, like this: $price = 100; $product = "Ipad 5"; $url = ""; $url .= "&Price=$price"; $url .= "&Product=$product"; $encodedUrl = rawurlencode($url); when clicking on this URL … : <a href="URLencode-recieve.php?rawEncodedLink=<?php echo $encodedUrl; ?>">rawUrlEncode Link</a> … it takes you to a page that has this coding: $encodedUrl = trim($_GET["rawEncodedLink"]); $decodedUrl = rawurldecode($encodedUrl); Both the $encodedUrl and $decodeUrl variables above have these values: &Price=100&Product=Ipad 5. However the GET method is NOT pulling the Price value from the parameter in the URL $price = trim($_GET["Price"]); echo "Price variable: " . $price; // this price variable is empty when echoing it. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 22, 2014 Share Posted June 22, 2014 Of course the parameters aren't read from the URL. They simply aren't there. What you have is a single URL parameter called “rawEncodedLink”. This parameter contains a bunch of URL-encoded characters. Since they're encoded, they do not have any special meaning for the URL. It's just data. The original “&” is now a literal character. It seems you want something entirely different. If you want to add actual parameters to the URL, you must not encode the “&” character. Use http_build_query() to create a proper list of URL parameters. Quote Link to comment Share on other sites More sharing options...
DLO2418 Posted June 23, 2014 Author Share Posted June 23, 2014 Of course the parameters aren't read from the URL. They simply aren't there. What you have is a single URL parameter called “rawEncodedLink”. This parameter contains a bunch of URL-encoded characters. Since they're encoded, they do not have any special meaning for the URL. It's just data. The original “&” is now a literal character. It seems you want something entirely different. If you want to add actual parameters to the URL, you must not encode the “&” character. Use http_build_query() to create a proper list of URL parameters. Thanks! I thought once you decoded the string, the parameters can be read. I'll test with http build query! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 23, 2014 Share Posted June 23, 2014 I thought once you decoded the string, the parameters can be read. Not sure what you mean. PHP parses the URL parameters and sets the $_GET superglobal before the script runs. What you do within the script is your business. If you want to update $_GET with some new value, you'd have to do that yourself (but of course you shouldn't and just use the correct parameters from the beginning). Quote Link to comment 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.