Solved

display just domain

Posted on 2006-11-06
5
210 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

756 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