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! 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 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. 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? 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']; 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. Link to comment https://forums.phpfreaks.com/topic/266500-get-site-url/#findComment-1365715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.