Recognizing Wildcard Subdomains with PHP

Discussion in 'PHP' started by AHA7, Sep 27, 2007.

  1. #1
    Hello,

    I have wildcard DNS enabled at my host so that any subdomain points to my main domain directory. I want to make a script that shows the appropriate content for the requested subdomain but the problem is:

    How can I find out (using PHP) what subdomain was requested by the user and so show the right content corresponding to the requested subdomain?
     
    AHA7, Sep 27, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Use $_SERVER['HTTP_HOST'] and remove your actual domain from it.

    Or if there are not dots in the subdomain, you can do:
    
    $subdomain = current(explode('.', $_SERVER['HTTP_HOST']));
    
    PHP:
     
    nico_swd, Sep 27, 2007 IP