Hi,

I am using the following code to retrieve the full url in the address bar:

$host = $SERVER['HTTP_HOST'];
$self = $
SERVER['PHP_SELF'];
$query = !empty($SERVER['QUERY_STRING']) ? $SERVER['QUERY_STRING'] : null;
$url = !empty($query) ? "http://$host$self?$query" : "http://$host$self";

Although, it doesn't seem to include variables on the end of the url.

For example, in a url like the one below:

http://www.phpbuilder.com/board/newthread.php?do=newthread&f=2

I'd like to also retrieve the "do=newthread&f=2" where at the moment it is only retrieving the "http://www.phpbuilder.com/board/newthread.php"

Thanks for any help,
~Oni.

    You need to use the $_SERVER['REQUEST_URI'] variable.

    I set up a quick test page

    <?PHP echo $_SERVER['REQUEST_URI']; ?>

    and called it with:
    test.php?x=2&file=yes
    which output:
    /test.php?x=2&file=yes

    So you'd wanna tack that into your code that gets the url up to that point.

    Maybe something like:

    <?PHP
    echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    ?>
    

    Edit: I just double checked the code above, and that worked for me. It output:
    scriptsamurai.com/test.php?x=2&file=yes

      (EDIT: Looks like Horizon beat me to it. 🙂 )

      I tried your code on my PC, and it seemed to work fine. However, since it seems that certain $SERVER values don't get set in certain environments, maybe you could try:

      $host = $_SERVER['HTTP_HOST'];
      $request= $_SERVER['REQUEST_URI'];
      $url = "http://$host$request";
      
        Write a Reply...