views:

224

answers:

3

Running Mac OS X 10.5.8, with PHP 5.2.11 Pre-installed. Using Coda 1.6.10.

I'm writing PHP files, and then preview them running from file, not server. This was working fine till I tried PHP includes. These don't work as a relative path, only as an absolute from the root of the drive.

Is there any way I can use statements like

include_once "common/header.php";

without specifying my entire file path like so :

include_once "/Volumes/Macintosh HD/Users/neil/Desktop/Website/ColoredLists_v1.0/common/base.php";

,where ColoredLists_v1.0 is the directory with all the website files in it. I tried solutions like prepending _SERVER[DOCUMENT_ROOT] or dirname(File) to the file paths, but that didn't work as the variables were not set. Is there any easy way to do this, or a configuration I can change so that it looks in a specific directory by default instead of looking at the drive root? Currently, echo_include_path shows .:

When I include this line at the start of the script, it works:

set_include_path('/Volumes/Macintosh HD/Users/neil/Desktop/Website/ColoredLists_v1.0');

However, if I want to do this for all my scripts, I can't seem to make the change permanent. Even after I edited the Unix include_path in my php.ini, it doesn't seem to work.

UPDATE: I finally decided that the easiest sureshot way was to run the Apache server locally. It comes preinstalled with Mac, so didnt face much trouble there. I modified the httpd.conf to only allow connections from localhost, thus alleviating my security fears. Ofcourse, this still opens up port 80, but I'm behind a router, so I'm gonna hope I'm not very exposed. And Coda includes a great features in 'Sites', where I can set the local url, so it works brilliantly now. Only downside is, now, after code edits, I need to manually refresh the preview.

+2  A: 

You can try this method.

require_once(dirname(__FILE__) . '/example.php');
scopus
A: 

Try

set_include_path(
    '/Volumes/Macintosh HD/Users/neil/Desktop/Website/ColoredLists_v1.0' .
    PATH_SEPARATOR . 
    get_include_path());

in a shared include file

or edit your php.ini and change the include_path variable (I'm using MAMP so can't tell you the exact path to php.ini)

Steve
A: 

It truly is an include_path issue. The default seems to be .:/usr/lib/php; perhaps if you launched the PHP command from the directory in which are your scripts, it would be fine?

zneak