westexasman Posted August 27, 2008 Share Posted August 27, 2008 Having a bit of an issue with absolute/relative urls. I have MAC running OS 10.5.4, Apache 2.2, PHP 5.2.5, MySQL 5.0.67 and phpMyAdmin 2.11.8.1. Things work great, it took me a while, but I finally have all of these apps running soundfully with each other and can develop nicely. I am, however, running into an issue which I would like some help with. I will first list my vhost settings and any other pertinent information that could help this process. Here is the document root in my http.conf file: DocumentRoot "/Library/WebServer/Documents" Here are important settings in the httpd-vhosts.conf: <VirtualHost *:80> DocumentRoot "/Users/CDB/Sites" </VirtualHost> #IndieViz Local Site Listen 1001 <VirtualHost *:1001> DocumentRoot "/Users/CDB/Sites/indieViz/httpdocs" ServerName 10.0.1.182:1001 </VirtualHost> <Directory /Users/CDB/Sites/indieViz/httpdocs> Allow from all </Directory> Ok, now on to my issue: I access my development site listed at 10.0.1.182:1001 and in the index.php page are the following lines include("/include/lib.php"); <img src="/img/banner_contest_269x195.jpg" width="269" height="195" border="0"> When the page is served, it cannot find the /include/lib.php but it CAN find the /img/banner... file. There is both an img folder and an include folder in the httpdocs dir (the ROOT dir). So, what is the reason that /include doesn't resolve to the root, but /img does? The reason I need /include to work is that this file is included on many files deep within the site structure. I really don't want to type in ../../include and ../include every time I want to include this file, so, any help would be greatly appreciated. I hope this makes sense, if not, please ask, I will try my best to explain. Thanks for any help, Clay Quote Link to comment https://forums.phpfreaks.com/topic/121575-absoluterelative-urls-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 27, 2008 Share Posted August 27, 2008 The leading slash in the file system path in - include("/include/lib.php"); refers to the root of the current disk. Quote Link to comment https://forums.phpfreaks.com/topic/121575-absoluterelative-urls-help/#findComment-627057 Share on other sites More sharing options...
westexasman Posted August 27, 2008 Author Share Posted August 27, 2008 OK So, include("/include/lib.php"); and <img src=/image/file.jpg> are differect? the src=/ is not referring the the root of the current disk but the include("/include/lib/php"); is? If that is the case, how would I go about fixing that. It doesn't make much sense, honestly, is this a php issue, why would /include/ refer to system root and not my document root? How would I go about making it refer to the document root, php.ini?? Thanks again, Quote Link to comment https://forums.phpfreaks.com/topic/121575-absoluterelative-urls-help/#findComment-627081 Share on other sites More sharing options...
PFMaBiSmAd Posted August 27, 2008 Share Posted August 27, 2008 An include is executed by php on the server. Unless you specify a protocol wrapper, it operates using a file system path, where a leading slash is the root of the current disk. A src="..." is executed by a browser and it can only operate using a URL. A leading slash in a URL causes the browser to form a url starting at the domain root. I recommend forming an absolute file system path as follows - include($_SERVER['DOCUMENT_ROOT'] . "/include/lib.php"); Quote Link to comment https://forums.phpfreaks.com/topic/121575-absoluterelative-urls-help/#findComment-627094 Share on other sites More sharing options...
westexasman Posted August 28, 2008 Author Share Posted August 28, 2008 Thank you, that worked perfectly. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/121575-absoluterelative-urls-help/#findComment-627814 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.