sgt_fireman Posted July 31, 2012 Share Posted July 31, 2012 Hey guys, So I'm wanting to get the site URL, but only the domain name part... for example, if the page a user was on is, www.example.com/test.php I'de want to just be able to get the www.example.com part, without the test.php, Up to now I've tried both $_SERVER["REQUEST_URI"] and $_SERVER["PHP_SELF"] however these both just output the test.php part, I don't know any more things that could do this.. and I can't find any of them on google so? Does anyone know anything about doing this? Thanks for the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/ Share on other sites More sharing options...
floridaflatlander Posted July 31, 2012 Share Posted July 31, 2012 I think this is it $url = dirname($_SERVER['PHP_SELF']); be sure to clean it with htmlentities or strip_tags and if you're inserting into a db mysqli_real_escape_string Quote Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/#findComment-1365700 Share on other sites More sharing options...
Christian F. Posted July 31, 2012 Share Posted July 31, 2012 If you run a print_r ($_SERVER); you should be able to find the index yourself. Either that, or by looking in the PHP manual. Quote Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/#findComment-1365701 Share on other sites More sharing options...
sgt_fireman Posted July 31, 2012 Author Share Posted July 31, 2012 I'm afraid that's just outputting a forward slash florida, and christian, because it's going into an automated system I do just need the URL alone, but I shall take a look in the PHP manual, thanks, while I'm searching, anyone else know any alternatives? Quote Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/#findComment-1365707 Share on other sites More sharing options...
floridaflatlander Posted July 31, 2012 Share Posted July 31, 2012 sorry try $url = $_SERVER['HTTP_HOST']; Quote Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/#findComment-1365712 Share on other sites More sharing options...
sgt_fireman Posted July 31, 2012 Author Share Posted July 31, 2012 I've managed to get it working with $_SERVER['SERVER_NAME'], Thank-you very much guys, and thank's florida. Quote Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/#findComment-1365715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.