Results 1 to 10 of 17
-
26th Aug 2012, 04:09 PM #1OPMemberWebsite's:
FileShoppe.netPHP problem handling urlencoded '&' (%26) char
Hello all,
A script we are working on deals with passing file names in the URL (via $_GET). Some files contain the '&' symbol in the name.
& is the separator in PHP to identify the new $_GET variable.
We typically use urlencode($theString) to encode 'funny' characters to be URL safe. However, PHP seems to treat the encoded '&' value in exactly the same way as if it were not encoded.
Here is an example of the problem.
File name is Q&A.jpg
The script may be like this
<?php
$fileName = $_GET[fileName];
echo $fileName;
?>
If the url in the browser was script.php?fileName=Q&A.jpg, the output would be Q.
If you url encode the file name, the url would appear as script.php?fileName=Q%26A.jpg
However the output is still just Q without the '&A.jpg'.
Similarly, we have tried using rawurlencode, but this does not fix the problem either.
Anyone familiar with this problem and know a fix?FShoppe Reviewed by FShoppe on . PHP problem handling urlencoded '&' (%26) char Hello all, A script we are working on deals with passing file names in the URL (via $_GET). Some files contain the '&' symbol in the name. & is the separator in PHP to identify the new $_GET variable. We typically use urlencode($theString) to encode 'funny' characters to be URL safe. However, PHP seems to treat the encoded '&' value in exactly the same way as if it were not encoded. Here is an example of the problem. Rating: 5
-
26th Aug 2012, 04:28 PM #2It begins...
Not too sure, but I remember a bit vaguely that this used to happen because the browser is itself decoding the urlencoded char before it sends the actual GET request. This obviously has a 'fix', if you will. I just can't seem to remember it at the moment. I'll dig into my archives, see if I have a similar issue I encountered and fixed in the past.
-
26th Aug 2012, 04:45 PM #3You can call me G
urlencoded string fetches '&' character without issues here..
Tested this code snippet:
PHP Code:
<?php
if(isset($_GET['var'])) {
echo $_GET['var'];
}
?>
Regards,
Gaurav
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
-
26th Aug 2012, 04:53 PM #4Respected Developer
after encoding URL with urlencode() , did u decode it by urldecode on output?
PHP Code:<?php
//$_GET[fileName] == Q%26A.jpg
$fileName = $_GET[fileName];
echo urldecode($fileName);
?>Bots Development | Web Development | Wordpress Customization | PSD Conversion
Life has many twists and turns in it, you have to take what you are given and use it for the best.
-
26th Aug 2012, 05:12 PM #5OPMemberWebsite's:
FileShoppe.netHi mRAza,
No I did not. This is not required as the superglobal $_GET is already url decoded. Decoding a second time may result in unexpected and unwanted problems.
Guarav, it doesnt work for me
---------- Post added at 06:03 PM ---------- Previous post was at 05:57 PM ----------
Okay, the code I wrote above actually DOES work. Something is wrong somewhere else, but I'm not sure where or why.
---------- Post added at 06:12 PM ---------- Previous post was at 06:03 PM ----------
Okay found the problem! But not the solution.
In fact the urlencoding DOES work, however, aparantly not in conjunction with apache's mod_rewrite.
Instead of somedomain.com/script.php?fileName=Q%26A.jpg (which works), I have been using somedomain.com/file/Q%26A.jpg (which doesnt work). Evidently, the mod_rewrite is breaking it.
Any ideas?
-
26th Aug 2012, 05:14 PM #6You can call me G
Post the Rewrite you've defined. That might help sorting out the problem
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
-
26th Aug 2012, 05:24 PM #7OPMemberWebsite's:
FileShoppe.netEssentially, the rule is:
RewriteRule ^file/([^/]+)/?$ script.php?fileName=$1 [NC]
-
26th Aug 2012, 05:48 PM #8You can call me G
http://blog.perplexedlabs.com/2008/0...al-characters/
URL Encode twice
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
-
26th Aug 2012, 05:50 PM #9OPMemberWebsite's:
FileShoppe.netencoding twice is not really an option as it will break other things.
-
26th Aug 2012, 06:00 PM #10Respected Developer
Edit: try this
PHP Code:RewriteRule ^file/([^/]+)/?$ script.php?fileName=$1 [NC,B]
Reference: [B] Flag , you might also need [QSA] FlagBots Development | Web Development | Wordpress Customization | PSD Conversion
Life has many twists and turns in it, you have to take what you are given and use it for the best.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
[Help] Block Spesial Char WHen Reg new username
By -sky- in forum vBulletinReplies: 0Last Post: 14th Dec 2011, 02:48 AM -
Handling over my website to someone trustworthy..,
By souvikroy1111 in forum Community CooperativeReplies: 1Last Post: 4th Aug 2011, 02:52 PM -
Small Footer Problem (<div> problem ??)
By Ashleyuk1984 in forum Technical Help Desk SupportReplies: 2Last Post: 26th Jan 2011, 02:53 PM -
[Selling] Short Url Site, 2 Char domain, Unique Design
By ChaoscripT in forum Completed TransactionsReplies: 0Last Post: 7th Sep 2010, 03:09 PM -
[Shared] Best int-char.com (warez linking iz allowed)
By Int-char.com in forum ArchiveReplies: 3Last Post: 19th Dec 2008, 08:42 AM
themaPoster - post to forums and...
Version 5.22 released. Open older version (or...