|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-07 18:54 UTC] main at springtimesoftware dot com
Description:
------------
I searched the bug database, but could not find this problem addressed.
This is a simple case using default configurations where a client JavaScript script sends a plus sign and a space as an argument as part of a URL to a server.
The script constructs the URL using the JavaScript 'escape' function, as recommended:
URL='www.example.com/example.php?Arg='+escape('+ ');
The server, running Apache and PHP, automatically runs urldecode (that is, I think it does; I could not find this documented in the PHP manual even after I did a lot of searching).
The PHP code
$Arg=$_GET["Arg"];
receives the string as " " (two spaces) instead of the expected "+ ". This is not a bug, but documented behavior of urldecode!
My request for a feature is this: add a runtime-accessible configuration option to suppress any default decoding of GET, POST, and other such arrays. Then the programmer can use rawurldecode to decode arguments properly.
Note: Although I only mentioned plus sign and space above, I really want to pass a string that can contain characters with any byte value, 0 to 255. This is to support cryptology protocols.
David Spector
Springtime Software
Reproduce code:
---------------
Let me know if you really need a test case. It would include a client page and a server page.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 10:00:01 2025 UTC |
Oops, I should have said that escape('+ ') gives '+%20'. On the PHP side, the "+" is considered an alias for " ", so the script sees " " (urldecode converts "+" into " " and "%20" into " "). I stand by the wording in the feature request. DavidI'm with David on this. On the client-side, I'm using the JavaScript escape() function to encode data for sending to the server using a POST ajax request. (Original bug report refers to $_GET, but this is also affecting $_POST) The server sees both plus signs "+" and "%20" as spaces. And yes, PHP is seeing the plus, untouched by Apache, as I can prove using: echo file_get_contents("php://input"); // Display raw POST This is very frustrating. I'm currently getting around this by parsing the raw POST data manually (above), and not using the pre-parsed $_POST data.Since I encountered the same problem in php, I wondered the cause of bug is really the php. Chosing another script language (python) to attest, in python (cgi), following code with query "q=c++" yields output of: {'q': ['c ']}. This shows that plus-sign is replaced with blank space independently on language (at least not only in php). I found a solution (not fundamental) to receive query arithmetic characters as raw string: rawurldecode(urlencode($whatever_qs)) It behaved as if blank space is restored to plus-sign (or other arithmetics sign). * index.py #!/usr/bin/python import cgi,os print "Content-Type: text/plain; charset=utf-8" print print cgi.parse_qs(os.environ['QUERY_STRING']) Shinobu Y.My fault, this is accturally not a bug. There is no need to use rawurlencode, otherwise, it will cause " + " become "+++"。 The value contained "+" in both $_GET and $_POST must have been decoded before passed to php, and then it has been decoded by url_decode again in php leading "+" become " "。 Apache may be able to do that, one possiable cause is mod_rewrite module. Because everything must be decoded before mod_rewrite to work, after that, it doesn't encode again. This is what exactly happend. " + " --------> "+%2B+" --------> " + " --------> " " apache mod_rewrite php Use "B" FLAG for mod_rewrite can fix this, see http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b