Welcome to WebmasterWorld Guest from 18.104.22.168 , register , free tools , login , search , subscribe , help , library , announcements , recent posts , open posts Subscribe to WebmasterWorld
URL parameter values not being received when using rawurlencode rawurlencode not allowing URL parameters to be received Dlo2418 msg:4681927 11:02 pm on Jun 22, 2014 (gmt 0) 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. How can the GET method receive the URL parameters when using rawurlencode? Thanks
lucy24 msg:4681946 2:27 am on Jun 23, 2014 (gmt 0)
Do you get the same results if you tweak the code so the starting URL has the form blahblah.php?price=one&product=two instead of blahblah.php?rawEncodedLink=&price=one&product=two ? The idea is to rid your php of any excuse, no matter how slim, to act up. penders msg:4681959 7:48 am on Jun 23, 2014 (gmt 0)
However the GET method is NOT pulling the Price value from the parameter in the URL This is correct. The way you have coded it you only have one URL parameter, ie. "rawEncodedLink" that contains the value "&Price=100&Product=Ipad 5" (unencoded). You would need to manually split this up to access to the "Price" and "Product" values (which you can do). The $_GET array is populated by PHP much earlier in script execution - at the very start of the request - when the URL is encoded with just a single URL parameter. As lucy24 says, if you want separate $_GET params in your target page you need to pass them as separate params in the request. Only urlencode the parameter values, not the entire query string, and urlencode(), not rawurlencode() in this instance (which is necessary for encoding the URL path). Dlo2418 msg:4682143 11:48 pm on Jun 23, 2014 (gmt 0)
Lucy and Penders - thanks for the advice. Separating the params worked: $price = 100; $product = "Ipad 5"; $url1 .= "$price"; $url2 .= "$product"; $encodedUrl1 = rawurlencode($url1); echo "Encoded URL1 var: " . $encodedUrl1; echo "<br><br>"; $encodedUrl2 = rawurlencode($url2); echo "Encoded URL2 var: " . $encodedUrl2; echo "<br><br>"; <a href="URLencode-recieve3.php?q=<?php echo $q_shopping; ?>&price=<?php echo $encodedUrl1; ?>&product=<?php echo $encodedUrl2; ?>">rawUrlEncode Link</a> Then on the recieving page, the params were rcvd: $Price = ($_GET["price"]); echo "Price variable: " . $Price; echo "<br>"; $Product = ($_GET["product"]); echo "Price variable: " . $Product; echo "<br>"; Again, thanks!