reading subdomain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    #1

    reading subdomain

    hi all
    i have a wildcard subdomain that will redirect all subdomains to one page. this page is a php script that will read the what subdomain they entered and if it is valid it will redirect to the apporiate page and if not it will go the the home page. the reason i am doing this is because of a client who apparently has major intelligence issues. but the problem is that i don't know how to get the full url they entered in.
    'http://subdomain.dumbc lient.com' the script is realy quite simple but i can't get that url and it is probaly some function that i just can't find below is the code that will process that so you can understand what i am doing a little better.

    [PHP]
    <?php
    $a = 'http://subdomain.yours ite.com'; //will need the function to get the domain here
    $sub = explode('.', $a);
    $new_sub = explode('/', $sub[0]);


    echo '<pre>';
    echo var_dump($new_s ub);
    echo '</pre>';
    //do weird stuff with $new_sub[2]
    ?>
    [/PHP]

    thanks for all past present and future help

    eric
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    #2
    hi all
    i found a function that will work

    for all those who want to use it here you go

    [PHP]
    function selfURL()
    {
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
    $protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s;
    $port = ($_SERVER["SERVER_POR T"] == "80") ? "" : (":".$_SERVE R["SERVER_POR T"]);
    return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
    function strleft($s1, $s2)
    {
    return substr($s1, 0, strpos($s1, $s2));
    }
    [/PHP]

    and have a var = selfURL()
    and it works perfectly

    thanks

    eric

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Thanks for sharing your solution.

      Ronald :cool:

      Comment

      Working...