Solved

display just domain

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now