PHP include does not work

Help with installation and general calendar setttings

PHP include does not work

Postby hgk » Tue Sep 21, 2010 2:36 pm

Hi Chris, I've been browsing the forum and read everything posted about the php include function, yet haven't been able to find a solution so far. Here's the situation:

I have an index.php which includes (switch) the other php files. Those files use the include as well, and I would like to include the calendar in one of those. This shouldn't give any problems. When I go to the index page of the calendar, it shows the calendar perfectly. However, including it shows nothing. Here is the code used:

Code: Select all
if(!file_exists($the_file)) die("<b>".$the_file."</b> not found");
else {
   print "file found!";

I do get the print, so it is not as if the file hasn't been found. I'm not running it on a windows server. No idea how come it fails to include, so any thoughts would be more than welcome!
Posts: 1
Joined: Tue Sep 21, 2010 2:19 pm

Re: PHP include does not work

Postby chris » Wed Sep 22, 2010 10:38 am

You are not actually testing as to whether the file is included.
You *are* checking if it exists (which clearly it is as it getting past that checkpoint).
The problem with include() is that it only returns a warning if the file is not included, it does not actually stop the rest of the code from being executed.
Personally I would recommend that you use require() rather than include() as this does return a fatal error and stop the code.
If for some reason you have to use include() you might want to add some code to actually test if the file is finally included.

As to the reason why it is not being included, that is hard to tell without actually playing with the code.
The path "looks" OK but each server is it's own world :(

Can you turn on error reporting so that the page shows the php warnings - that might give you some insight as to why the file is not actually being included.

User avatar
Site Admin
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests