4

I have a website that just moved from one server to another. On the old server the get-parameters of a request were automatically 'url decoded'. Now, on my new server, when I try to retrieve a GET parameter I don't get the url decoded value but the encoded value.

Because besides the server nothing in my project changed, this makes me think this is a PHP setting (maybe in php.ini?).

How can I make PHP automatically decode my GET parameter values?

Terrabythia
  • 2,031
  • 3
  • 19
  • 29
  • 4
    `Warning The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results. ` – Hanky Panky Feb 22 '16 at 10:03
  • @HankyPanky the OP say they are **undecoded** – fusion3k Feb 22 '16 at 10:09
  • 2
    Then according to that note on manual, Problem lies somewhere else. Cause there is no version of PHP that will not decode a properly encoded GET automatically. However there are a lot of comments here about JavaScript encoded values not getting through properly. http://php.net/manual/en/function.urldecode.php – Hanky Panky Feb 22 '16 at 10:10
  • This sounds very strange... I don't know any php.ini set to change this. Besides, there you seem to be the only with this problem. **Triple check** that files are exactly the same. There are on your new server some RewriteRule? Maybe it is a [server related issue](http://stackoverflow.com/questions/6520484/mod-rewrite-urlencoding-an-already-urlencoded-querystring-parameter-any-way-to). – fusion3k Feb 22 '16 at 10:16
  • Thanks for your comments. I am sending the parameters via a JavaScript AJAX request to my server (using encodeUriComponent), so maybe the problem lies there somewhere. I still find it strange that it did work properly on the old server and not on the new, but I will ask my new hosting provider if they have any idea on what it could be. – Terrabythia Feb 22 '16 at 10:44
  • Its been a while, does anyone have a solution here? Im having a very similar problem: **1.** javascript encodeURIComponent is being used to build a string used as the src param for an iframe. **2.** retrieving these params using $_GET but the values have NOT been decoded (this is happening on our staging server, development environment doesnt have the issue) Has anyone any suggestions? Many thanks! – Jon TJ May 16 '17 at 10:41

1 Answers1

0

I've just encountered the same issue and it turned out to be due to an Apache rewrite rule on the new server that did not exist on the old server. The rule re-encoded an already encoded URL. I was lucky to have noticed the URL rapidly change in Chrome's Developer Tools Network tab and realised that a redirection must have been responsible.

In my case the solution was to entirely remove the .htaccess file that contained the rule, but such a change could also have been caused by rules in the Apache server configuration files.

In the case that a rewrite rule is present but required, one can disable URL encoding by adding NE (no escape) to the rewrite flags.

Ian Mackinnon
  • 13,381
  • 13
  • 51
  • 67