-3

I know (and see) that this question has been asked for about a thousand times, but, after search and search, and somewhat confusing answers, i'm still looking for a right answer.

All I need is to identify my domain from url like (http://www.example.com; or http://example.com or www.example.com or just example.com) (no subdomains-for now) with PHP.

I'm creating a simple website, but hosted on 2 seperate domains (with same contents), and i need to identify on which site (domain) user is, in order to display the right logo, disclaimer etc.

Thanks.

Satch3000
  • 47,356
  • 86
  • 216
  • 346
uollaa
  • 17
  • 1
  • 4
  • 1
    See: http://stackoverflow.com/questions/1459739/php-serverhttp-host-vs-serverserver-name-am-i-understanding-the-ma – Satch3000 May 25 '15 at 17:40
  • just try some of the thousand examples you have and see what happens. I'm 100% sure one of them gets you there – h3n May 25 '15 at 17:47
  • tried, tried, tried, nothing seem to work, whatever i do it renders me the entire link, all in need is to separete 2 domain extensions (.com and .net - same domain name) simple IF loop. please help – uollaa May 25 '15 at 19:44
  • Are you saying you want to extract and use the domain extension, rather than the whole domain? See my expanded answer below where I do an if on the full name, and then find the extension utilising a reverse strpos (strrpos) to locate the full stop. – MortimerCat May 25 '15 at 21:29
  • Does this answer your question? [PHP how to get the base domain/url?](https://stackoverflow.com/questions/17201170/php-how-to-get-the-base-domain-url) – Yousha Aleayoub Aug 02 '21 at 17:57

1 Answers1

1

for getting server name: $_SERVER['SERVER_NAME'] for reference: http://php.net/manual/en/reserved.variables.php

rSa
  • 11
  • 1