PHP include

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChrisMcHugh
Forum Newbie
Posts: 1
Joined: Tue May 05, 2009 6:04 am

PHP include

Post 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??
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: PHP include

Post 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.
nwhiting
Forum Newbie
Posts: 18
Joined: Sun May 03, 2009 8:30 pm

Re: PHP include

Post 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
Post Reply