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
therat
Forum Commoner
Posts: 62 Joined: Wed Oct 01, 2003 2:44 pm
Location: London
Post
by therat » Wed Jan 28, 2004 4:03 pm
I am using this code to store the referer in a database.
Code: Select all
if (isset($_SERVER['HTTP_REFERER'])) {
$refer = $_SERVER['HTTP_REFERER'];
}else {
$refer = ' [ -- Direct Hit -- ] ';
}
This stores the whole URL in the database. What I want is to store the domain name only. How do I change the above to acheive this.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Jan 28, 2004 4:39 pm
Code: Select all
if (isset($_SERVER['HTTP_REFERER'])) {
$parsed_url=parse_url($_SERVER['HTTP_REFERER']);
$refer = $parsed_url["host"];
}else {
$refer = ' [ -- Direct Hit -- ] ';
}
[php_man]parse_url[/php_man]
therat
Forum Commoner
Posts: 62 Joined: Wed Oct 01, 2003 2:44 pm
Location: London
Post
by therat » Thu Jan 29, 2004 1:16 pm
Thanks, works perfectly.