Results 1 to 3 of 3

Thread: Referring Domain Problem

  1. #1
    Join Date
    Nov 2013

    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

  2. #2
    Join Date
    Aug 2004
    You can look at $_SERVER['HTTP_HOST'], perhaps something like:
    PHP Code:
    $subDomain array_shift(explode('.'$_SERVER['HTTP_HOST']));
    $subDomain) {

    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Sep 2013
    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.
    strad solutionswww.stradsolutions.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center