www.webdeveloper.com
Results 1 to 8 of 8

Thread: urlencode() issues

  1. #1
    Join Date
    Feb 2012
    Posts
    102

    Question urlencode() issues

    Hello,

    I am having an issue passing a % sign via the $_GET method. I am running the variable through urlencode() before sending it to the browser and it is adding all the + signs between words but it does nothing with the % and this is causing a 404 error. I have also tried using rawurlencode() but it is the same effect with the error. This is an issue for me as I am coding my own forum and I cannot control if a user uses % instead of percent. Can anyone think of why urlencode() is not encoding the % sign?

    Here is my code for the url

    PHP Code:
    <a href="reply.php?tid=' . $tid . '&pid=' . $messages['post_id'] . '&body=' . urlencode($messages['message']) . '>Reply & Quote</a> 

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    The posted code does not have a closing double-quote for the HREF value.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2012
    Posts
    102
    Yes, I know I didnt post the code exactly as it is the html is all there and working fine its the urlencode () that isnt working that is why I asked what else I could do because whenever a user puts a % sign into their post it is not encoded with %25 as it should be.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Works fine for me:
    Code:
    C:\Users\xxxxxxx>php -r "echo urlencode('%x%x%');"
    %25x%25x%25
    C:\Users\xxxxxxx>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Feb 2012
    Posts
    102
    ok so it is encoding correctly or so it looks like it when I click the link but for some reason any url with a % in the $_GET variable causing this error:

    "Not Acceptable

    An appropriate representation of the requested resource /reply.php could not be found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

    For some reason it is only urls with a % in the $_GET variable that are causing this error. Do you have any idea what could be causing this?

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Perhaps we need to see the actual PHP code in question? Maybe $message is too long for use in a URL?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Feb 2012
    Posts
    102
    Quote Originally Posted by NogDog View Post
    Perhaps we need to see the actual PHP code in question? Maybe $message is too long for use in a URL?

    What is the limit? I read that it is over 2000 characters for the lowest limit. When I checked the number of characters in my url that I was passing it was 299. I posted the php that was being used, here is the message that was in the variable.

    "Currently the show only measures contestant's success based on % of total body weight lost. Do you think they should measure total body fat percentage? Voice your opinions here."

    Here is the encoded URL:

    "http://www.realitytvaddict.com/reply.php?tid=1312&pid=1714&body=Currently+the+show+only+measures+contestant%27s+success+based+on+%2 5+of+total+body+weight+lost.+Do+you+think+they+should+measure+total+body+fat+percentage%3F+Voice+you r+opinions+here."

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    My suspicion is something in your web server's configuration, perhaps some sort of (misguided?) security setting that does not allow some aspect of that string in a URL? At least, if I send it to a couple other domains, I don't get the "Not acceptable..." error (though of course I get a 404).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles