General Community > Scripting Help
Capture subdomain
CokeCan:
Hi,
Does anybody knows how I can read and show on the php the subdomain that the URL has got?
For example, if the user get in at http://blue.mysite.com ir should show "blue" and if the user gets in http://red.mysite.com it should show "red", I saw some sites that are doing this but I don't know how to do it :(
Thanks in advanced!
[Unknown]:
I'd do this with a quick index.php that includes another php file they all include... for example...
<?php
define('PAGE_COLOR', 'red');
include_once('/home/me/public_html/black/index.php');
?>
And then in the main index.php, start it with:
<?php
if (!defined('PAGE_COLOR'))
define('PAGE_COLOR', 'black');
...
?>
-[Unknown]
CokeCan:
Thanks Unknown but I don't need to to write colors :-\ I just used it as an example. I need it to write change the text at the html, expecialy at the title. For example:
http://unknown.mysite.com -> <title>Hello Unknown</title>
http://cokecan.mysite.com -> <title>Hello Cokecan</title>
Do you know how to do it?
Aquilo:
this is how I do it for new hosting accounts at xtram
--- Code: ---<?
$startcheck = $HTTP_SERVER_VARS["HTTP_HOST"];
$startcheck = ereg_replace ('http://', '', $startcheck);
$MyName = explode('/', $startcheck);
$MyName = $MyName[0];
?>
--- End code ---
then you can do:
echo '<title>Hello '.$MyName.'</title>';
[edit]oops you only wan't the name...
--- Code: ---<?
$startcheck = $HTTP_SERVER_VARS["HTTP_HOST"];
$startcheck = ereg_replace ('http://', '', $startcheck);
$MyName1 = explode('/', $startcheck);
$MyName2 = explode('.', $MyName[0]);
$MyName = $MyName2[0];
// optional if your server can also use www.username.site.tld
//$MyName = ($MyName2[0] != 'www') ? $MyName2[0] : $MyName2[1];
?>
--- End code ---
CokeCan:
Thanks Aquilo!
That's what I need! :D
but is it posible to get just the subdomain name and not all the url?
Navigation
[0] Message Index
[#] Next page
Go to full version