gerkintrigg Posted July 12, 2007 Share Posted July 12, 2007 Hi. I'm trying to work out the site root so that I can use this script: <?php // start the session session_start(); header("Cache-control: private"); //IE 6 Fix // Your main website URL $url='http://www.full_address.co.uk/'; // minumum number of days to be booked by the system: include $url.'includes/db.php'; $q="SELECT no_of_days FROM no_of_days WHERE id=1 LIMIT 1"; $sql=mysql_query($q); $r=mysql_fetch_array($sql); $minimum_no_of_days_booking=$r['no_of_days']; ?> Problem is that I can't include the db connection script using the $url variable... Any ideas how I can determine the root path? I reference this include file from lots of different folders and sub-folders and really need it to be versatile enough to handle it. Quote Link to comment Share on other sites More sharing options...
trq Posted July 12, 2007 Share Posted July 12, 2007 $_SERVER['DOCUMENT_ROOT'] Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 12, 2007 Author Share Posted July 12, 2007 genius! thanks Quote Link to comment Share on other sites More sharing options...
vynsane Posted July 12, 2007 Share Posted July 12, 2007 just for the info, that only works if your domain name IS in the doc root of the server. for purposes of those using domain pointers that go to a sub-folder of the doc root, this works as well: $_SERVER['HTTP_HOST'] Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 12, 2007 Author Share Posted July 12, 2007 so HTTP_HOST is probably better as a rule then? Quote Link to comment Share on other sites More sharing options...
trq Posted July 12, 2007 Share Posted July 12, 2007 HTTP_HOST returns your domain name, nothing to do with a file path. Im not sure a completely understand what vynsane is going on about. Quote Link to comment Share on other sites More sharing options...
vynsane Posted July 12, 2007 Share Posted July 12, 2007 so HTTP_HOST is probably better as a rule then? not a rule by the slightest, but if you need to get an absolute url path relative to a domain name that isn't pointing to the doc root, then $_SERVER['DOCUMENT_ROOT'] won't work for what you need. i use it on my site to create absolute url's on a site that has three separate domain aliases that point to a subfolder of my doc root. i now see that it wouldn't apply in this case - i guess i was too groggy when i posted. anyway, i first discovered it in this thread: http://www.phpfreaks.com/forums/index.php/topic,129379.msg541897.html#msg541897 Quote Link to comment 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.