Click to See Complete Forum and Search --> : Server Side Includes & PHP Includes


philaweb
07-26-2004, 01:38 PM
OK, it's time for me to grab the bull by the horns. :)

I've tried several times in the past to create some includes for PHP pages, but to no avail. Tried to find some solid tutorials on both SSI and PHP includes, but none of the tutorials really answers my questions.

What I would like to know is how I create an include within a PHP document (and I have tried to follow some of the tutorials link to from this board).

Is it only possible to include a PHP file to a PHP file, or can I include a .txt, .html or even a .shtml file to a PHP file?

TIA :)

LordShryku
07-26-2004, 10:35 PM
You can include any sort of file you want to in a php file. Whatever it is is how it will show though. So if you include a html or text file, it will just spit it to the screen. But if you included a php file with a couple functions in there, nothing will output to the screen until you call them.

include("/path/to/file.php");
# or
require 'C:\\some\\file.txt';

The parens aren't neccesary since it's not really a function.

There's also require_once (http://php.net/require_once) and include_once (http://php.net/include_once).

philaweb
07-27-2004, 04:50 AM
I've attached a test PHP file I've created.

The test file is online *right here* - and as you can see nothing from those three included files is shown. :(

For comparence this file (http://www.lettonica.info/postcards/ww2_soviet/) is the SSI version.

Can anyone tell me what I'm doing wrong? I'm not very savvy at PHP, yet.

Edit: Link removed

LordShryku
07-27-2004, 09:26 AM
It looks like you're using the relative path. Try the absolute path and I bet it'll work for you.

include('/var/www/ssi/udm-menu.txt');

You may want to see if the $_SERVER['DOCUMENT_ROOT'] variable shows your real doc root. Makes it a bit easier when including these things.


include($_SERVER['DOCUMENT_ROOT'].'/ssi/udm-menu.txt');

philaweb
07-27-2004, 12:20 PM
Originally posted by LordShryku
It looks like you're using the relative path. Try the absolute path and I bet it'll work for you.

Yes! That's what I was missing. Thank you very much! :)