Solved

display just domain

Posted on 2006-11-06
5
215 Views
Last Modified: 2008-03-06
hello,
I have this in my page
<? echo $_SERVER["HTTP_HOST"]; ?>
but if i type in the (address bar) www.domain.com
I see the echo as www.domain.com
is there a way to only display domain.com ?
0
Comment
Question by:Sabrin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Expert Comment

by:eheimer
ID: 17886730
have you tried $_SERVER["SERVER_NAME"] instead?  The output of that should depend on what you have setup as the domain in your web server config (httpd.conf).

The other thing you could do is:

<?php
    $host = $_SERVER["HTTP_HOST"]
    if (!(strpos($host, 'www.')==false)) {
        $host = substr($host, 4);
    }
    echo $host;
?>
0
 

Author Comment

by:Sabrin
ID: 17886828
this code

<?php
    $host = $_SERVER["HTTP_HOST"]
    if (!(strpos($host, 'www.')==false)) {
        $host = substr($host, 4);
    }
    echo $host;
?>

is not working
0
 

Author Comment

by:Sabrin
ID: 17886832
this works

    $host = $_SERVER["HTTP_HOST"];
    if (!(strpos($host, 'www.')==true)) {
        $host = substr($host, 4);
    }
    echo $host;
0
 

Author Comment

by:Sabrin
ID: 17886833
is there a ways to have all subdomains too ?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 17887638
Use http://pl.php.net/manual/en/function.explode.php to chop the host into parts.
$host_arr = explode('.', $host);
$curr_domain = "";
while($last = array_pop($host_arr)) {
 $curr_domain = $last . ($curr_domain ? "." :  "" ) . $curr_domain;
 print "$curr_domain\n";
}
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question