Hi

I need to extract the full url including any trailing vars in a query string.

say my url is www.mysite.com/something.php

$myUrl = 'http://'.$SERVER['HTTP_HOST'].$SERVER['PHP_SELF'];

will correctly return: 'www.mysite.com/something.php'

but if my url is say: www.mysite.com/something.php?var1=blah&var2=blahblah&var3=whatever

using $myUrl = 'http://'.$SERVER['HTTP_HOST'].$SERVER['PHP_SELF']; is still only gonna give me 'www.mysite.com/something.php'

Anybody know a snippet of code to get the full url?

cheers 🙂

    sneakyimp wrote:

    you will find this page helpful:
    http://us2.php.net/reserved.variables

    $SERVER has all kinds of other information in it. in particular, you may find $SERVER['QUERY_STRING'] and $_SERVER['REQUEST_URI'] helpful.

    cheers fella that worked

    $myUrl = 'http://'.$SERVER['HTTP_HOST'].$SERVER['PHP_SELF'];

    $queryString = $_SERVER['QUERY_STRING'];

    echo "total url = $myUrl?$queryString";

    sweet, thanks mate 🙂

      Write a Reply...