PDA

View Full Version : PHP includes help needed!



Mr. Pickle
11th May 2006, 3:17 AM
I can't get it to work.. : (

http://i5.photobucket.com/albums/y182/RaichuEMINA/phpincludescrnsht3.png
http://i5.photobucket.com/albums/y182/RaichuEMINA/phpincludescrnsht2.png
http://i5.photobucket.com/albums/y182/RaichuEMINA/phpincludescrnsht1.png

In the last screenshot (phpincludescrnsht1) I added the <html></html> and <body></body> tags shortly after and it still didn't work..

Magma Leader Maxie
11th May 2006, 2:36 PM
Try this instead:



// if head.html and your php file are in the same directory
<?php require('./head.html'); ?>

// if head.html is in another diretory called "dir"
<?php require('./dir/head.html'); ?>

// if head.html is somewhere on the net :)
<?php require('http://www.site.com/head.html'); ?>

Mr. Pickle
12th May 2006, 9:47 AM
http://i5.photobucket.com/albums/y182/RaichuEMINA/screenshotforphpinclude.png

Still doesn't work..

The image is in the same folder.

Magma Leader Maxie
21st May 2006, 1:38 AM
Then try the getcwd() function.



define('DIR', ($cwd=getcwd()? $cwd, '.'));
require(DIR . 'PATH_TO_FILE');

where PATH_TO_FILE is the local path to whatever you're including.

♪Crystal Mew♪
21st May 2006, 3:30 AM
since they aren't dynamic files did you try something like this?



echo file_get_contents('header.html');


did you also try:


include('header.html');

Magma Leader Maxie
21st May 2006, 5:01 AM
since they aren't dynamic files did you try something like this?



echo file_get_contents('header.html');


did you also try:


include('header.html');


No real need to use file_get_contents()... plus there have been some incompatibility issues with that function, depending on the PHP version.

If require didn't work, include won't either. They are related functions.

If all else fails, ask your host to give you the full relative path to your directory (for example www\root\xy\htdocs) and then use that to require the file. But I think that ♪Crystal Mew♪'s suggestion to use include() makes sense because usually, only vital program components (such as class files, for example) need to be required. However, it's a good practice to use the './' before the filename if the file is in the same directory, or '../' if it's in one directry lower, etc.