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.
You can look at $_SERVER['HTTP_HOST'], perhaps something like:
$subDomain = array_shift(explode('.', $_SERVER['HTTP_HOST']));
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Below is the code by which you can get the subdomain url:
Simplest and fastest solution.
$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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)