/    Sign up×
Community /Pin to ProfileBookmark

Referring Domain Problem

First off – apologies if this isn’t the correct forum – but couldn’t really see a better home for it.
I want to build a site that directs a visitor to a page depending on which subdomain they used when they visit my site. I would build this in php, but the issue is more about how the site knows which subdomain was used in the first place (which is why this probably isn’t a php question). In my domain manager panel I can set redirects for any subdomain based on a wildcard, but I can’t see how the original subdomain information can be forwarded to my site.
eg Someone browses to red.mydomain.com and gets forwarded by the domain manager to mysite.com. The script (if it could be made to work) would identify that the original URL entered was red.mydomain.com, and forward them to a red page. If someone typed blue.mydomain.com, then they might go to a different page – hopefully you can see the idea, although please don’t ask why!
I think this boils down to how to configure a domain manager subdomain redirect such that the original subdomain is retained as the refering URL. If that isn’t possible, any other thoughts about how to solve this conundrum? I want to be able to do this for maybe hundreds of different subdomains, so setting up each subdomain redirect on the domain manager panel isn’t an option since they can only support 100.
Thank you ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 02.2013 — You can look at $_SERVER['HTTP_HOST'], perhaps something like:

[code=php]
$subDomain = array_shift(explode('.', $_SERVER['HTTP_HOST']));
switch($subDomain) {
case 'red':
include 'red.php';
break;
case 'blue':
include 'blue.php';
break;
default:
include 'default.php';
}
[/code]
Copy linkTweet thisAlerts:
@priyankagoundNov 07.2013 — Below is the code by which you can get the subdomain url:

[U]Simplest and fastest solution.[/U]

$sSubDomain = str_replace('.example.com','',$_SERVER['HTTP_HOST']);

For storing the url in your database or in your page you can try out with below solutions:

Basic table structure could be

id - ip_address(or user_id) - subdomain

Then do an if statement checking the database for their IP or user ID.

<?

/* database checking code, etc, assuming we're returning $result from the query */

$subdomain = @mysql_result($result,0,'subdomain');

if($subdomain != '') header('Location: '.$subdomain.'.yourdomain.com');

?>

Hope this helps.
×

Success!

Help @Steverob1066 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...