PHP relative include require incude_once require_once


The concept of relative is always from the file being executed.

ralph l mayo explains with an example here

Note that the relative starting point is always from the file being executed. Ie., if you have:

/include.php
/myapp/index.php
/myapp/otherinclude.php

if index.php (the file the users requests) includes ‘../include.php’, include.php must include otherinclude as ‘otherinclude.php’ and not ‘myapp/otherinclude.php’

For this reason if you have includes spanning several directories or includes that are used in different contexts, it’s often easier to define a root path and include absolutely.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s