PHP Include Path Problems
Setting the include path is really confusing me. I must be missing something important.
So I have the following scripts in the public_html folder of my server.
photoGallery.php
header.php
I have my htaccess file set to redirect a url with the following structure to photoGallery.php
RewriteRule ^gallery/([^/]+)/([0-9]+)-([^/]+)$ photoGallery.php?imageName=$2 [L]
So something like this...
http://localhost/gallery/roofing/1-picture-of-roofing
Would resolve to...
http://localhost/photoGallery.php?imageName=1
The problem is there is a PHP include inside of photoGallery.php that will not resolve if the URL has been rewritten.
include 'header.php'
So I would like to set the php include path so it will resolv开发者_开发知识库e no matter what. Here's what I've tried...
set_include_path(get_include_path() . PATH_SEPARATOR . "../../../");
include 'header.php';
I've also tried setting the path like so...
// get_include_path() returns .:/opt/lampp/lib/php
set_include_path(get_include_path() . PATH_SEPARATOR . "/opt/lampp/public_html");
include 'header.php';
I've never been able to successfully set the include path. What am I doing wrong?
You could try :
include($_SERVER['DOCUMENT_ROOT'] . '/header.php');
Add a call to: http://php.net/manual/en/function.getcwd.php to the same script as
set_include_path(get_include_path() . PATH_SEPARATOR . "/opt/lampp/public_html");
And then adjust "/opt/lampp/public_html" according to the getcwd() output.
精彩评论