Welcome to WebmasterWorld Guest from 54.196.35.120

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

URL parameter values not being received when using rawurlencode

rawurlencode not allowing URL parameters to be received

     
11:02 pm on Jun 22, 2014 (gmt 0)

New User

joined:Jan 22, 2014
posts: 7
votes: 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
2:27 am on June 23, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13062
votes: 304


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.
7:48 am on June 23, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 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).
11:48 pm on June 23, 2014 (gmt 0)

New User

joined:Jan 22, 2014
posts:7
votes: 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!