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
Solved

display just domain

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP breaks when used in Wordpress template file 3 30
Uploading a CSV Data Import via PHP & MySql 3 29
How do I show metrics with PHP or Javascript 6 32
Ajax and PHP 9 29
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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