What is "my" url?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ealhajj
Forum Newbie
Posts: 1
Joined: Wed Sep 04, 2002 12:45 pm

What is "my" url?

Post by ealhajj »

How do I get the url string of the current .php page? For example:

I am writing a page "hello.php" that resides on http://www.webserver.com. I want to display the url string "www.webserver.com/hello.php". How do I get that string?

Thanks,
ealhajj
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

Code: Select all

<?php
echo $_SERVER&#1111;SERVER_NAME].$_SERVER&#1111;PHP_SELF];
?>
This is ... but take a look at
http://www.php.net/manual/en/reserved.v ... les.server
:wink:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you don't want PHP to have to do extra work looking for constants named SERVER_NAME and PHP_SELF try:

Code: Select all

echo $_SERVER&#1111;'SERVER_NAME'].$_SERVER&#1111;'PHP_SELF'];
and to view the contents of the $_SERVER array:

Code: Select all

echo '&lt;pre&gt;';
print_r($_SERVER);
echo '&lt;/pre&gt;';
Mac
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Oh yes, the sexy $DOCUMENT_ROOT is used alot in my stuff. :D
Image Image
Post Reply