cinos11 Posted February 13, 2010 Share Posted February 13, 2010 What i need help on is getting php to include the website name ex: subdomain.domain.com Then what it will do is strip ".domain.com" so that way it only shows subdomain as text on the page. I will be using this for my wildcard subdomains. That way if someone puts in bobby.domain.com it will show bobby as the text on the page. Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/ Share on other sites More sharing options...
teamatomic Posted February 13, 2010 Share Posted February 13, 2010 $domain='bobby.domain.com'; $parts=explode(".",$domain); (count($parts)==3)?$sub = $parts[0]:$sub=''; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/#findComment-1011720 Share on other sites More sharing options...
cags Posted February 13, 2010 Share Posted February 13, 2010 I don't exactly understand what you asking here. This doesn't seem like it has anything to do with PHP per se. You can use mod_rewrite (Apache module) to redirect the sub-domain to a page that could do this, but this isn't really relative to PHP since the only PHP involved would be... echo $_GET['subdomain']; If you can confirm it's the mod_rewrite section you need help with I can move the topic to the appropriate board. NB: This will also only work if the host (or you if your in control of it) has the Nameserver set up to pass all sub-domains through. Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/#findComment-1011741 Share on other sites More sharing options...
cinos11 Posted February 13, 2010 Author Share Posted February 13, 2010 The post above cags will not work because i when the page loads with any random subdoman such as: bob.domain.com,jake.domain.com,dog.domain.dom. That it will show only bobby because the PHP only says to use that then explode part of it. For the above i tried echo $_GET['subdomain']; on my website and nothing showed. I think what that php code says is what i need but its not working. As for your note above saying will only work etc. Yes im in control of my website, as its hosted on my computer. And all non setup subdomains are set up to be redirected to one webpage using a wildcard of *.domain.com Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/#findComment-1011868 Share on other sites More sharing options...
mattal999 Posted February 13, 2010 Share Posted February 13, 2010 print_r(explode(".", $_SERVER['SERVER_NAME'])); Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/#findComment-1011876 Share on other sites More sharing options...
teamatomic Posted February 13, 2010 Share Posted February 13, 2010 $domain= $_SERVER['HTTP_HOST']; $parts=explode(".",$domain); (count($parts)==3)?$sub = $parts[0]:$sub=''; echo "$sub"; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/#findComment-1011878 Share on other sites More sharing options...
cinos11 Posted February 13, 2010 Author Share Posted February 13, 2010 Thanks you the above post solved my problem. Link to comment https://forums.phpfreaks.com/topic/191947-include-subdomain-name-only-in-page/#findComment-1011881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.