Jump to content

URL parameter values not being received when using rawurlencode


DLO2418

Recommended Posts

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.