www.webdeveloper.com
Results 1 to 14 of 14

Thread: urlencode HELP

  1. #1
    Join Date
    Nov 2006
    Posts
    28

    urlencode HELP

    Is it possible to urlencode a URL via $_GET? Cause i've tried it..... doesn't seem to work, while $_POST works perfectly.

    I've noticed the character '#' being left out (and everything behind it) e.g. www.domain.com/files/list.htm#thelist , so 'thelist' dissapears including the '#'.

    Code:
    $url = urlencode($_GET['url'])
    Anyone?

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    I think you need to apply urlencode() BEFORE you create the URL and use urldecode() on the receiving side.

  3. #3
    Join Date
    Nov 2006
    Posts
    28
    Quote Originally Posted by NightShift58
    I think you need to apply urlencode() BEFORE you create the URL and use urldecode() on the receiving side.
    Well, how can i place the encode even earlier? I mean right now i placed it at the moment it gets it from the browser ($_GET), i can't do it any earlier than that...

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    In your receiving script (or called script), you should DECODE what has been received and not ENCODE.

    urlencode() needs to be on the page that has the link that was clicked on (the sending page).

    urldecode() needs to be on the page that is being called by that click (the receiving page).

  5. #5
    Join Date
    Nov 2006
    Posts
    28
    Quote Originally Posted by NightShift58
    In your receiving script (or called script), you should DECODE what has been received and not ENCODE.

    urlencode() needs to be on the page that has the link that was clicked on (the sending page).

    urldecode() needs to be on the page that is being called by that click (the receiving page).
    Okay... so the user types in ?url=www.blahblah.com , it gets recieved by the script and does something with it, BUT when there are characters like # etc. in the URL it gets all screwed up, so i should DECODE the ?url= input?? Kinda odd because i didn't encode anything lol..

  6. #6
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Generally, most browsers do it automatically and servers, depending on their settings, do it as well.

    Why don't you just try it?

  7. #7
    Join Date
    Nov 2006
    Posts
    28
    Quote Originally Posted by NightShift58
    Generally, most browsers do it automatically and servers, depending on their settings, do it as well.

    Why don't you just try it?

    I tried just decoding the $_GET['url'] , STILL it same '#' problem...

  8. #8
    Join Date
    Jul 2005
    Location
    USA
    Posts
    909
    What is $_GET['url']?????

    You are saying you have a link like this:

    http://www.somesite.com/?url=http://...place.html#top

    And you want the value of it, so you are using:

    Code:
    <?php
    
    $url=$_GET['url'];
    
    ?>
    Bitter web veteran

  9. #9
    Join Date
    Nov 2006
    Posts
    28
    Quote Originally Posted by Webnerd
    What is $_GET['url']?????

    You are saying you have a link like this:

    http://www.somesite.com/?url=http://...place.html#top

    And you want the value of it, so you are using:

    Code:
    <?php
    
    $url=$_GET['url'];
    
    ?>
    Yes, i had that already (look at my first post). I put the user input in $url via $_GET, however when a '#' comes up it ignores it, THATS the problem...

  10. #10
    Join Date
    Jul 2005
    Location
    USA
    Posts
    909
    Let me try on my side...
    Bitter web veteran

  11. #11
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Sorry. I've been missing you're point about your problem being specifically with #.

    The fact is that starting with # and anything after that doesn't get passed to the server.

    That's used by the browsers to jump to a specified anchor. Server-side, you can't use as it doesn't get picked up.

  12. #12
    Join Date
    Jul 2005
    Location
    USA
    Posts
    909
    I think the issue is that the # needs to be escaped before the URL is sent. So your URL should be:

    http://somesite.com/?url=http%3A//blahblah.html%23top

    And then you won't have that problem
    Bitter web veteran

  13. #13
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    One has to question the practical use of using a # for server-side scripting. It doesn't add any thing to what can be done. The OP might as well use an additional get (&picketfence=top).

  14. #14
    Join Date
    Nov 2006
    Posts
    28
    Quote Originally Posted by Webnerd
    I think the issue is that the # needs to be escaped before the URL is sent. So your URL should be:

    http://somesite.com/?url=http%3A//blahblah.html%23top

    And then you won't have that problem
    Tried it and that works, but of course the user has to know that '#' is '%23'... which isn't likely... maybe it can be done with JS to automatically convert' #' into '%23' ? Just a thought because my knowledge of JS is pretty much none existent.
    Last edited by koolaid; 10-09-2007 at 01:37 PM.

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