0

How can I get the exact base url? for example:

if the user type like this: https://stackoverflow.com/ I have to get the same also and if like this: http://www.stackoverflow.com/. i have to get the same url also.

thanks in advance

Community
  • 1
  • 1
rayss
  • 637
  • 2
  • 9
  • 19

2 Answers2

0

For URLs like:
localhost/myblog/
http://domain.com/blog/

use: get_site_url()

d.raev
  • 9,216
  • 8
  • 58
  • 79
0

The $_SERVER variable has a lot of values you may want to consider, one of them being $_SERVER['HTTP_HOST'] (if you want the site that's being queried).

$thisSite = 'http://'.$_SERVER['HTTP_HOST'].'/';

geting if they used a www, use stripos:

if (stripos($_SERVER['HTTP_HOST'],'www.') === 0) { /* they used www */ }
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • How would I know if the user typed in the browser has www? – rayss Dec 22 '10 at 01:14
  • Hi Brad, Thank you for your reply I really appreciate it but your code its not working because if the user typed: "http:// www.sample.com" and when i print the $_SERVER['HTTP_HOST'] it will get only sample.com. – rayss Dec 22 '10 at 01:42
  • Well, them I'm out of ideas and not quite sure you can get that value. Most forums/web services offer a config file for you to supply the "root domain", which implies it's not easily retrieved. – Brad Christie Dec 22 '10 at 02:00