News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Capture subdomain

Started by CokeCan, August 27, 2003, 07:26:25 PM

Previous topic - Next topic

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

#3
this is how I do it for new hosting accounts at xtram

<?
$startcheck = $HTTP_SERVER_VARS["HTTP_HOST"];
$startcheck = ereg_replace ('http://', '', $startcheck);
$MyName = explode('/', $startcheck);
$MyName = $MyName[0];
?>

then you can do:
echo '<title>Hello '.$MyName.'</title>';

[edit]oops you only wan't the name...


<?
$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];
?>


CokeCan

Thanks Aquilo!
That's what I need! :D
but is it posible to get just the subdomain name and not all the url?

Aquilo

I was editing while you posted I updated the last post!

CokeCan

#6
That one isn't working for me :(

The first one works ok :-\

Aquilo

sorry for got a 1!


<?php
$startcheck 
$HTTP_SERVER_VARS["HTTP_HOST"];
$startcheck ereg_replace ('http://'''$startcheck);
$MyName1 explode('/'$startcheck);
$MyName2 explode('.'$MyName1[0]);
$MyName $MyName2[0];
?>


CokeCan


CokeCan

This is for another website bt is it posible to get just the domain name with any subdomain? :D

Aquilo

I dont know what you mean, but...
<?php
$startcheck 
$HTTP_SERVER_VARS["HTTP_HOST"];
$startcheck ereg_replace ('http://'''$startcheck);
$MyName1 explode('/'$startcheck);
$MyName2 explode('.'$MyName1[0]);
$MyName $MyName2[0];
?>


the last line:
$MyName2[0] = subdomain
$MyName2[1] = domain
$MyName2[3] = tld


Advertisement: