Get domain

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
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Get domain

Post by S_henry »

In php, how can we get the domain name? For example, if i put/run my system in the domain server called http://www.abc.com/, what is the code to get that domain name server (http://www.abc.com/)? Anybody can help me pls?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Run this snippet:

Code: Select all

<?php
  echo '<pre>';
    print_r ($_SERVER);
  echo '</pre>';
?>
To extract the exact domain, check out a function like ereg()
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post by lazersam »

$referred_from = $HTTP_REFERER; Should get the address the visitor came from.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

lazersam wrote:$referred_from = $HTTP_REFERER; Should get the address the visitor came from.
Don't rely on that too much. Some browsers do not send that variable and it can be easily spoofed.
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

OK. Perfect. Thanx guys.. :D
Post Reply