2

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 resolve 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?

1
  • BTW, Mod_Rewrite doesn't affect includes. Commented Jan 26, 2010 at 22:00

2 Answers 2

5

You could try :

include($_SERVER['DOCUMENT_ROOT'] . '/header.php');
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.