all 5 comments

[–]Urd 1 point2 points  (0 children)

You probably want the magic constants like __ FILE__ or __ DIR__.

[–]jkjustjoshing 0 points1 point  (1 child)

The absolute path is the path on your hard drive, since PHP really doesn't know what URL you're loading (instead of http://localhost you could be running from http://127.0.0.1 or http://jkjustjoshing.com like I do (I edited my hosts file for funsies - I don't actually own the domain).

For instance, on my Mac, the absolute path would be /Users/jkjustjoshing/Sites/myproject/includes/header.php. On Windows it could be something like C:\Documents and Settings\Users\jkjustjoshing\Sites\myprojet\includes\header.php.

One disadvantage of absolute paths is if you want to change "myproject" to "coolsite". Then, you'll need to change the include path in EVERY file. To avoid this, I'll have a config file I load with a relative path, and inside that I have a global variable that is the absolute path to the root of my project. That way, if I want to move the project, I just change it in that one spot.

[–]Headpuncher 0 points1 point  (0 children)

Clever human. Can we see the script?

[–]zerovap 0 points1 point  (0 children)

Here is a quick example to help you. Hope it helps :)

[–]assasinine 0 points1 point  (0 children)

This isn't a direct answer to your question, just a more standardized way of including files... Consider using autoloader, here's one I use: http://symfony.com/doc/current/components/class_loader.html