Using PHP to grab the absolute URL of the script?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-06-08T08:15:21Z Indexed on 2010/06/08 8:22 UTC
Read the original article Hit count: 123

Filed under:

Basically, I want my script to output its absolute URL, but I don't want to statically program it into the script. For example, if my current URL is http://example.com/script.php I want to be able to store it as a variable, or echo it. i.e. $url = http://example.com/script.php;

But if I move the script to a different server/domain, I want it to automatically adjust to that, i.e. $url = http://example2.com/newscript.php;

But I have no idea how to go about doing this. Any ideas?

© Stack Overflow or respective owner

Related posts about php