-4

How to get current site URL without http:// or https:// for both domain and subdomain ?

Input - > http://www.example.com/ | Output -> www.example.com
Input - > http://site.example.com/ | Output -> site.example.com
Input - > example.com/ | Output -> www.example.com

I tried to use $_SERVER['SERVER_NAME'] but that's not working exactly.

dcaswell
  • 3,137
  • 2
  • 26
  • 25

3 Answers3

3

This answer can help you to retrieve the URL. Once you have that, have a look at the parse_url() function to process it:

$parsed = parse_url('http://www.example.com');
echo $parsed['host']; // www.example.com
Community
  • 1
  • 1
George Brighton
  • 5,131
  • 9
  • 27
  • 36
1

Try this

echo $_SERVER['REQUEST_URI'];

For more check the documentation

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
0

I think $_SERVER['HTTP_HOST'] is what you're looking for.

Dragony
  • 1,712
  • 11
  • 20