GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Nov-2003, 12:21
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about

PHP: Display Domain Name


How would I display the domain name of the page I am at. Lets say it it www.desilva.biz/something.html and I want to display desilva.biz. Exactly like that. No www, or http:// included.

I have tried
Code:
<?php echo htmlentities( $_SERVER['REQUEST_URI'] ); ?>
but it does not quite work.

The code above displays a frontflash '/'. And not the domain.extension.
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #2  
Old 27-Nov-2003, 12:59
Allowee's Avatar
Allowee Allowee is offline
Regular Member
 
Join Date: May 2003
Location: The Netherlands
Posts: 339
Allowee has a spectacular aura about
things like
PHP Code:

$_SERVER['HTTP_HOST'];$_SERVER['SERVER_NAME']; 


will display the hostname without http://

but sometimes it include www.
but a simple
PHP Code:

$hostname = str_replace('www.', '', $hostname); 


will fix that.

and then you can just append the request uri
__________________
Pastebin
PHP Documentation Site
Allowee's Blog http://allowee.net
  #3  
Old 27-Nov-2003, 23:17
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Well, I put
PHP Code:

<?
$_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'];
$hostname = str_replace('www.', '', $hostname);
?>


And it does not work. http://www.mrbobdouglas.com/new/index.php
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #4  
Old 28-Nov-2003, 02:33
Allowee's Avatar
Allowee Allowee is offline
Regular Member
 
Join Date: May 2003
Location: The Netherlands
Posts: 339
Allowee has a spectacular aura about
Try this, which is a full script

PHP Code:

<?php$hostname = $_SERVER['SERVER_NAME']; $hostname = str_replace('www.', '', $hostname); echo $hostname . htmlentities($_SERVER['REQUEST_URI']);?>


which displays
Code:
allowee.no-ip.com/test.php
on my box
__________________
Pastebin
PHP Documentation Site
Allowee's Blog http://allowee.net
  #5  
Old 28-Nov-2003, 12:38
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Still does not show up for me. http://www.mrbobdouglas.com/new/

Also, I would rather just display the domain name, and not the full path to the page.

When someone signs up for a hosting account, they will automatically get the files that belong in their account, I want the index file to read 'This is the new home of [DOMAIN NAME]'
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #6  
Old 29-Nov-2003, 00:21
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Like Allowee has already said, $_SERVER['SERVER_NAME'] is probably your best bet, however the super global array $_SERVER is only available to a PHP script in the newer versions of PHP...

If you want to troubleshoot this 'issue' yourself, just bring up a phpinfo and go through the values under the PHP Variables table on the page...
  #7  
Old 29-Nov-2003, 01:21
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
This is what finally works for me
PHP Code:

<?php
$hostname = $_SERVER['SERVER_NAME']; 
$hostname = str_replace('www.', '', $hostname); 

echo $hostname;
?>


Thanks for the help guys
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
Last edited by BobbyDouglas : 29-Nov-2003 at 02:25.
  #8  
Old 11-Feb-2009, 09:50
youssef93 youssef93 is offline
New Member
 
Join Date: Feb 2009
Posts: 1
youssef93 is on a distinguished road

Re: PHP: Display Domain Name


So sorry for needing to bump this thread but will this code also work for a subdomain?

I want to use it on 404 error pages. For example,

subdomain.domain.com/wrong_page

is an invalid url. It will redirect to, for example, domain.com/404.html

Can I display to the visitor that he might want to check out subdomain.domain.com to find what he wants?

Can you please provide a simple script? Thanks!
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate a data change php form mjfmn MySQL / PHP Forum 4 20-Oct-2003 10:37
[Linux] Installing PHP --with-mcrypt JdS Web Hosting Forum 0 20-Aug-2003 09:40
Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More EyotaHosts Web Hosting Advertisements & Offers 0 28-Jun-2003 14:54
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 17:14
Hosting under $8/month: 10-20GB Transfer, 300-600MB Space, PHP, MySQL, Domain Name! fcolor Web Hosting Advertisements & Offers 0 28-Feb-2003 05:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:59.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.