PDA

View Full Version : PHP include problem


namsu
10-11-2004, 11:31 AM
Hello
I got my hosting, it seems to be working great except for one problem.
I use php to include a template. The location of it is in public_html/inc
Public_html is my home folder where I have my index file and so forth.
In files from this folder everything is included ok.
However my stories are in the Public_html/news folder. Files from
there come up with the following error:

Warning: main(inc/templatehead.htm): failed to open stream: No such file or directory in /usr/home/namsu/public_html/news/siteguide.php on line 7

Warning: main(): Failed opening 'inc/templatehead.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /usr/home/namsu/public_html/news/siteguide.php on line 7


The code I use is:
<?php include("inc/templatehead.htm"); ?>

I've also tried:
<?php include("/inc/templatehead.htm"); ?>
<?php include("./inc/templatehead.htm"); ?>

Nothing works. It fails to find that directory(.:/usr/lib/php), and I can't see it from ftp either. Any suggestions?

wildfire
10-11-2004, 03:25 PM
Are you using any kind of web portal system, such as phpNuke or TikiWiki? If so, I would suggest reinstalling them, as it is possible that not all of the files were copied. They are in the Scripts section of cPanel and are very useful. Also, cPanel makes it easy as pie to set up. Sorry if that didn't help.

redblizzard
10-11-2004, 04:28 PM
Try:
<?php include("../inc/templatehead.htm"); ?>

mahangee
10-11-2004, 04:36 PM
Also you could give include_once instead of include.

namsu
10-11-2004, 07:06 PM
Well I figured it out. The php.ini file is pointing elsewhere(not my site).
I could have used a relative link:
<?php include("../inc/templatehead.htm"); ?>

The problem there is that if I ever change the directory structure I'd have to edit every file. What I wanted was a globally defined ~home for php. What you have to do is edit the .htaccess file
If your site is megastar.hostmatrix.com add the following:

php_value include_path ".:/usr/home/megastar/public_html/"

Then you can just use <?php include("inc/includedfile.htm"); ?>
anywhere in your site when you need to include a php file. Really
simple.