PHP: Print string depending on domain or subdomain

Discussion in 'Programming' started by Alfahane, Apr 28, 2007.

  1. #1
    I need a PHP-script that shows/prints different strings depending on whether the current document is on a domain or subdomain. If it is on a subdomain it is to print different string depending on the first letter (a-z), if not a-z then yet another string is to be printed.

    The script must be tolerant to whether "www" is used or not.


    I need it ASAP. $10 thru paypal.
     
    Alfahane, Apr 28, 2007 IP
  2. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    I am interested !
    PM me with all the details !
     
    pulikuttann, Apr 28, 2007 IP
  3. champ_rock

    champ_rock Peon

    Messages:
    3,349
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    i am not exper but i think this can be done by something like this
    
    $exploded= explode (".", $array);
    
    Code (markup):
    then u need to add something which will automatically print out if the $explode[3] exists or not?

    if it exists then it means that it is a subdomain otherwise domain
     
    champ_rock, Apr 28, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    # Find subdomain
    preg_match('@^(www\.)?(.*)yourdomain\.com$@i',$_SERVER['HTTP_HOST'],$tmp);
    $sub = empty($tmp[2]) ? false : $tmp[2];
    unset($tmp);
    
    if ( $sub ) {
      # Subdomain - extract first character
      $first = substr($sub,0,1);
      if ( ctype_alpha($first) )
        # First char is A-Z
        include 'subdomaina-z.html';
      else
        # First char is not A-Z
        include 'subdomainnota-z.html';
    } else {
      # Main domain
      include 'maindomain.html';
    }
    PHP:
    Untested but should be something along those lines.
     
    rodney88, Apr 28, 2007 IP