Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Absolute/Relative URLs help |
|
Author |
|
westexasman
Joined: 27 Aug 2008 Posts: 2
|
Posted: Wed 27 Aug '08 17:32 Post subject: Absolute/Relative URLs help |
|
|
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:
Code: |
DocumentRoot "/Library/WebServer/Documents"
|
Here are important settings in the httpd-vhosts.conf:
Code: |
<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
Code: | include("/include/lib.php"); |
Code: | <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 |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 27 Aug '08 19:46 Post subject: |
|
|
The browser askd for the file in the doccument root which apache handles. PHP looks for files in the filessystem. And there is no /include/lib.php If you set there the path you have to use the relative one or use the correct absolute path like this example
Code: |
/Users/CDB/Sites/indieViz/httpdocs/include/lib.php
|
Hope that helps. |
|
Back to top |
|
westexasman
Joined: 27 Aug 2008 Posts: 2
|
Posted: Thu 28 Aug '08 16:22 Post subject: A solution |
|
|
First off, thanks James Blond for your info. I appreciate it. I have found another solution that works as well.
I have always despised posters that don't post the solution, if found. The generous posters (PFMaBiSmAd) over at PHPfreaks have provided a solution, here it is.
Quote: |
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 -
Code: |
include($_SERVER['DOCUMENT_ROOT'] . "/include/lib.php");
|
|
I hope this helps someone in the future. |
|
Back to top |
|
|
|
|
|
|