views:

279

answers:

4

I am trying to user header() to direct to a page above the document root. I'm running XAMPP so I'm trying to call a script above htdocs.

My problem is it gives me the 404 error and can't find the document.

My question: can you use header() to call a script above the document root or is it better to use an include() to accomplish this?

I was trying to be a good php programmer and keep all the scripts with passwords and database access above the htdocs folder.

Thanks in advance.

+3  A: 

No you can't. Anything above the document root does not have a URL, so therefore it is impossible. You want to use an include in a file below the root.

The reason you put all the password files above the root is so Users can't access them using a URL. This also means you can't redirect them there using a URL.

Chacha102
+1  A: 

You have to use an include; you can't redirect a user to anything that's not in the document root.

Eric Lamb
+1  A: 

You can't use header to accomplish this.

Header is used to send the browser to a specific URL - which you can't do when the URL is not within the server's servable directories.

Jani Hartikainen
+1  A: 

You can't use header to redirect to anything above the document root. A header redirect tells the browser to request this file instead of the current one, and the browser can only access URLs that the server is making available - which means the file is under the document root.

You might need to look into rewrite rules (on apache, other servers provide similar) to rewrite (or "map") public urls to scripts above the document root.

Brenton Alker