Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0

    Detecting Domain


    This may not be the right place for this so feel free to move it.

    I'm trying to figure out the best way to detect a domain in order to load the proper information (as in a multi tenant website). Like if I had
    50 domains that all went to one single website but each site displayed its own text, would I be using something in PHP to detect which domain is
    being called or is there a different method to handle this?
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,110
    Rep Power
    4103
    Code:
    $_SERVER['HTTP_HOST']
    That will contain the value of the Host: header which should contain the domain name used to access the website. Inspect that to determine what you want to do. Be sure to take into account the possibility that it doesn't match anything and respond appropriately.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    Thanks for the reply. So if I had 50 domains would I then run the result of $_SERVER through a boat load of if elseif statements until it matched and then go from there or is there a smarter way? Should I be considering
    Laravel for this type of thing?
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Originally Posted by bob8619
    run the result of $_SERVER
    The what?

    If your site has different content for different people then it must have that information stored somewhere, right? How is it stored? All you have to do is work in the hostname somewhere in there so you can look up the right information according to it.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    Yeah each sites information will be stored in a database. You mean work the hostname somewhere in the database or where? If it isn't apparent, I'm a rookie and this is all just an experiment for my own sake.

    I feel stupid posting what is probably a very amateur question but my searches haven't been of any value so here I am.
  10. #6
  11. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    "Will be" stored. So you haven't done anything yet...

    The database structures should relate each piece of information to a particular site, either directly in the table or naturally by use of a foreign key that itself is related to a site. Point is that all the data can be tied to a site. Makes sense, right? How else would you know who owns what content?

    So now that you have introduced the concept of "a particular site", all you have to do is include the domain name in there so you can look it up from the HTTP_HOST. Then all your queries for getting information can know which site's to find.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    Yes that's correct I haven't created any databases for this I've just been trying to learn how to check the domain, which I now know is by using the $_SERVER['HTTP_HOST'].

    I get the concept of what needs to be done but I don't know what it looks like. Is there just a single instance of $_SERVER['HTTP_HOST'] or is there one for every possible domain?
  14. #8
  15. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Originally Posted by bob8619
    Is there just a single instance of $_SERVER['HTTP_HOST'] or is there one for every possible domain?
    ...

    Like all variables, they exist while a script is running. There are no "instances" of a value: $_SERVER[HTTP_HOST] will only have one possible value while the script is running, but you don't know what the value is ahead of time - beyond what it represents, of course (ie, it being the domain name portion of the URL the user put into their browser). Like right now, the scripts running on this site are receiving "forums.devshed.com" as the one and only value; if the server ran other sites through the same codebase for another site, like what you're thinking of doing, then the HTTP_HOST would be a different one and only value.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    I'm just too much of a visual learner so without seeing how a task is done I'm just useless.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    12
    Rep Power
    0
    If you have multiple domains that point to the same IP address the proper way to serve unique content for each one is to setup a Virtual Host in Apache.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    Originally Posted by benanamen
    If you have multiple domains that point to the same IP address the proper way to serve unique content for each one is to setup a Virtual Host in Apache.
    You can have one single instance of a website with multiple domains usingthat method?
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    12
    Rep Power
    0
    Originally Posted by bob8619
    You can have one single instance of a website with multiple domains usingthat method?
    I am not clear on what you want. You have said two different things.

    Do you want multiple domains to go to the same exact single website or do you want multiple domains to go to unique content for each domain i.e. "different sites"
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    Originally Posted by benanamen
    I am not clear on what you want. You have said two different things.

    Do you want multiple domains to go to the same exact single website or do you want multiple domains to go to unique content for each domain i.e. "different sites"
    Sorry for the confusion. One website , multiple domains with the unique content coming from database
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    12
    Rep Power
    0
    If the content is different for each domain how are you calling this "one" website?
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    Just a typical multi-tenant situation, one single website being hosted. Then somehow using php to pull the proper data out of the db depending on which domain is being used.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo