+ Reply to Thread
Results 1 to 8 of 8

Thread: PHP Variable in URL

  1. #1
    webdev2009 is offline x10Hosting Member webdev2009 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    2

    Question PHP Variable in URL

    okay so i have my url which is


    Code:
    http://www.xxxxxxxx.x10hosting.com/beta/?url=http://www.facebook.com/home.php#/profile.php?id=xxxxxxxxxxxxxx&ref=nf#/profile.php?id=xxxxxxxxxxxxxx&ref=nf

    here is the code for the php page

    <?php

    $url_data = $_GET['url'];
    echo $url_data;

    ?>

    when i open the page it comes up with

    http://www.facebook.com/home.php

    and ends just before the HASH (#)

    do i have to encode the url or something? im new to php by the way so please be nice!

    many thanks

    Darren
    Last edited by webdev2009; 05-28-2009 at 10:54 AM.

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP Variable in URL

    Yes, there are special characters that need to be encoded, namely ampersand (&) and the greater than and less than symbols (<>). You can use the function htmlspecialchars() to encode strings so they are http safe.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    webdev2009 is offline x10Hosting Member webdev2009 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    2

    Re: PHP Variable in URL

    i have corrected it using another method, but thanks for your feedback anyway

    :biggthump

  4. #4
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: PHP Variable in URL

    thanks garrettroyce for the function, it will come in handy for me later on
    +REP

  5. #5
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP Variable in URL

    Quote Originally Posted by diabolo View Post
    thanks garrettroyce for the function, it will come in handy for me later on
    +REP
    Thank you

    Don't forget about it's counterpart: htmlspecialchars_decode() to do the reverse ;)
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP Variable in URL

    For URIs, urlencode/urldecode are more appropriate.

  7. #7
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP Variable in URL

    Quote Originally Posted by misson View Post
    For URIs, urlencode/urldecode are more appropriate.
    It's already been encoded once, since it's already a URI. I think the only characters we need escaped are ampersands. But that is definitely true for encoding the URI the first time.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP Variable in URL

    Quote Originally Posted by garrettroyce View Post
    It's already been encoded once, since it's already a URI. I think the only characters we need escaped are ampersands. But that is definitely true for encoding the URI the first time.
    I guess it depends on what he's using the URL for. It's not clear what the OP's purpose it. I was assuming he wanted to set the attribute of an element to the URI, in which case he'd want urldecode. If he's printing the URI as content, then you're right; htmlspecialchars() is the way to go. If he wants any of the "&ref=" arguments to be a part of $_GET['url'];, he'll need to use a URI encode function when the "http://www.xxxxxxxx.x10hosting.com/beta/?url=" URI is generated.

    If only the OP was more explicit about what zhe was doing and hir overall goal, we could be more helpful.

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. Pregunta sobre las Configuraciones PHP
    By Trevelin in forum Soporte
    Replies: 11
    Last Post: 04-28-2008, 01:50 PM
  4. My 2cents on Ruby vs PHP.
    By jwillia in forum Programming Help
    Replies: 0
    Last Post: 03-15-2008, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers