Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/121575-absoluterelative-urls-help/
Share on other sites

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,

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"); 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.