WEB php display URL in form

Discussion in 'OT Technology' started by MSTRMOO, Jul 15, 2008.

  1. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    hey how do i auto paste the current url in a form field?

    like.. i have a form, and in one of the text fields, the current url is pasted.

    im assuming this is fairly simple....
     
  2. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
  3. Deviance

    Deviance Can't you smell that smell? OT Supporter

    Joined:
    Jul 10, 2007
    Messages:
    4,994
    Likes Received:
    12
    Location:
    Rocky Mountain High
    // find out the domain:
    $domain = $_SERVER['HTTP_HOST'];
    // find out the path to the current file:
    $path = $_SERVER['SCRIPT_NAME'];
    // find out the QueryString:
    $queryString = $_SERVER['QUERY_STRING'];
    // put it all together:
    $url = "http://" . $domain . $path . "?" . $queryString;
    echo "The current URL is: " . $url . "<br />";


    // An alternative way is to use REQUEST_URI instead of both
    // SCRIPT_NAME and QUERY_STRING, if you don't need them seperate:
    $url2 = "http://" . $domain . $_SERVER['REQUEST_URI'];
    echo "The alternative way: " . $url2;
     
  4. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    sweet...

    no i actually want to keep the query strings..
     
  5. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    I can only see this becoming a catalyst for injection attacks. What site? :x: :)
     
  6. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    ok im a total noob so bare with me... why doesnt this seem to work? :o

    <?php $url=$_SERVER['REQUEST_URI']; ?>
    <input name="URL" type="text" value="<?php $url; ?>" />
     
  7. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
  8. crazybenf

    crazybenf Active Member

    Joined:
    Nov 14, 2001
    Messages:
    15,578
    Likes Received:
    3
    you need to print the $url var.. echo $url will work.

    Be warned it has the / in there too, so you'll need to strip that.
     
  9. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    thx guys. i used echo, it worked... dunno how i forgot that :o
     

Share This Page