including other files into a php file
#1
I had my index.htm working fine, but for various reasons I need it to be php.
However when I make it php, my includes don't work.
for example:
<?php
include '/php/text_rotator.php';
?>
doesn't work, it gives me an error:
Warning: Failed opening '../php/text_rotator.php' for inclusion (include_path='.:') in /usr/local/etc/httpd/vhosts/gregh.co.uk/ipaqsoft/index.php on line 48
however under the .htm version, this worked fine:
<!--#include virtual="/php/text_rotator.php"-->
any ideas?
thanks,
greg
However when I make it php, my includes don't work.
for example:
<?php
include '/php/text_rotator.php';
?>
doesn't work, it gives me an error:
Warning: Failed opening '../php/text_rotator.php' for inclusion (include_path='.:') in /usr/local/etc/httpd/vhosts/gregh.co.uk/ipaqsoft/index.php on line 48
however under the .htm version, this worked fine:
<!--#include virtual="/php/text_rotator.php"-->
any ideas?
thanks,
greg
#2
Scooby Regular
Hello again
The HTML version you were using is SSI, that's an Apacheism unrelated to HTML. SSI's 'virtual' directive will mean include the file relative to DocumentRoot, which is specified in your httpd.conf. Looks as if the PHP search path contains the CWD only (assuming the colon is a seperator), so you need to check the path that PHP is searching. I don't know the faintest thing about PHP though
Steve.
The HTML version you were using is SSI, that's an Apacheism unrelated to HTML. SSI's 'virtual' directive will mean include the file relative to DocumentRoot, which is specified in your httpd.conf. Looks as if the PHP search path contains the CWD only (assuming the colon is a seperator), so you need to check the path that PHP is searching. I don't know the faintest thing about PHP though
Steve.
#3
assuming /php/ is in your document root
<?
include("{$_SERVER["DOCUMENT_ROOT"]}/php/text_rotator.php");
?>
php will search the current directory by default, but you can just use the pre-defined document root variable to pull things and have it just work
<?
include("{$_SERVER["DOCUMENT_ROOT"]}/php/text_rotator.php");
?>
php will search the current directory by default, but you can just use the pre-defined document root variable to pull things and have it just work
#4
If you have an older version of PHP (pre 4.1.0 I think) you have to use just $DOCUMENT_ROOT instead of $_SERVER["DOCUMENT_ROOT"]:
include($DOCUMENT_ROOT . '/php/text_rotator.php');
Regardless of which you use, you might find the document root already has a trailing slash from the Apache set-up.
include($DOCUMENT_ROOT . '/php/text_rotator.php');
Regardless of which you use, you might find the document root already has a trailing slash from the Apache set-up.
Thread
Thread Starter
Forum
Replies
Last Post