Activity Stream
48,167 MEMBERS
62095 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1.     
    #1
    Member
    Website's:
    FileShoppe.net

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

    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

  2.   Sponsored Links

  3.     
    #2
    It 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.

  4.     
    #3
    You 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'];
    }

    ?>
    Forks fine on Chrome 21.0.1180.57 and FF 14.0.1

    Regards,
    Gaurav



    My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz

  5.     
    #4
    Respected 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);
    ?>
    Edit : My bad urdecode is bad thing :/ thanks for reminding me out
    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.

  6.     
    #5
    Member
    Website's:
    FileShoppe.net
    Hi 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?

  7.     
    #6
    You 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

  8.     
    #7
    Member
    Website's:
    FileShoppe.net
    Essentially, the rule is:

    RewriteRule ^file/([^/]+)/?$ script.php?fileName=$1 [NC]

  9.     
    #8
    You can call me G



    My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz

  10.     
    #9
    Member
    Website's:
    FileShoppe.net
    encoding twice is not really an option as it will break other things.

  11.     
    #10
    Respected Developer
    Edit: try this
    PHP Code: 
    RewriteRule ^file/([^/]+)/?$ script.php?fileName=$[NC,B
    I have just tested above, worked...

    Reference: [B] Flag , you might also need [QSA] Flag
    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.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 14th Dec 2011, 02:48 AM
  2. Handling over my website to someone trustworthy..,
    By souvikroy1111 in forum Community Cooperative
    Replies: 1
    Last Post: 4th Aug 2011, 02:52 PM
  3. Small Footer Problem (<div> problem ??)
    By Ashleyuk1984 in forum Technical Help Desk Support
    Replies: 2
    Last Post: 26th Jan 2011, 02:53 PM
  4. [Selling] Short Url Site, 2 Char domain, Unique Design
    By ChaoscripT in forum Completed Transactions
    Replies: 0
    Last Post: 7th Sep 2010, 03:09 PM
  5. [Shared] Best int-char.com (warez linking iz allowed)
    By Int-char.com in forum Archive
    Replies: 3
    Last Post: 19th Dec 2008, 08:42 AM

Tags for this Thread

BE SOCIAL