Page 1 of 1

PHP include

Posted: Tue May 05, 2009 7:47 am
by ChrisMcHugh
Okay, so I've not searched the forum for this, so I am sorry if I am repeating other people. However I find most people asking for help in the situation are doing more complicated projects than myself.

Anyway I am using a PHP include, to include a menu on each page. Although this is not the only way to do the job, I have been informed that I must use PHP includes to do so. So using another fuction isn't a solution.

Anyway in my includes I have used complete paths and I am receiving the following error. Note: I have removed the company name here as Im sure they wouldn't want me posting online about them.

Warning: include(http://www.[company.name].ac.uk/intranet/menu/menu.php) [function.include]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /web3/vhosts-faculties/business/intranet/committees/facultyboard/FacultyBoard.php on line 20

Warning: include() [function.include]: Failed opening 'http://www.[company.name].ac.uk/intranet/menu/menu.php' for inclusion (include_path='/web/service/php:/web/service/php/include:.') in /web3/vhosts-faculties/business/intranet/committees/facultyboard/FacultyBoard.php on line 20

I have heard a rumour that complete paths do not work with includes. Is this true??

Re: PHP include

Posted: Tue May 05, 2009 8:55 am
by jazz090
well compelte paths DO work, but by the looks of it, the directory or the file you are trying to access has some sort of protection on it either by .htacess or its configured in it directly.

Re: PHP include

Posted: Tue May 05, 2009 9:33 am
by nwhiting
complete paths will work with PHP, but there is absolutly no need to EVER use a complete path for including files unless they are on a remote server.

You should always use 1. Absolute paths, or 2.) Relative.

Using realtive paths your statement should be the following.

This is quessing that you are on the root of the folder structure (http://www.[company.name].ac.uk) is where you index.php file

Code: Select all

 
include('intranet/menu/menu.php');
 
and if you are in the intranet folder

Code: Select all

 
include('menu/menu.php');
 
Also, the error you are receiving is a Authorization error, htaccess is not allowing you to retrieve that file using HTTP