...

View Full Version : PHP Include



alex11
07-17-2012, 01:37 AM
PHP include feature wont work for me,

I have tried:

<?php
require($DOCUMENT_ROOT . "path to file/include-file.html");
?>

And Also:


<?php include 'header.php'; ?>

I'm not sure if it is XAMPP or the code.
The code also did not work on X10 hosting.
Any suggestions?

Thanks

DavidB3ck
07-17-2012, 04:10 AM
PHP include feature wont work for me,

I have tried:

<?php
require($DOCUMENT_ROOT . "path to file/include-file.html");
?>

And Also:


<?php include 'header.php'; ?>

I'm not sure if it is XAMPP or the code.
The code also did not work on X10 hosting.
Any suggestions?

Thanks

Perhaps header.php doesn't exist in the same directory as the file you are calling it from. Either way, try using header.php's absolute path.

Old Pedant
07-17-2012, 07:47 PM
Not to ask a silly question... are you sure that PHP is working, at all, for you?

Can you do something as simple as


<?php
echo "This PHP test worked.<hr/>\n";
?>

???

alex11
07-17-2012, 10:30 PM
Thank you for the tip.
The php code would not work in my header.html file, but it needs to be in a php document of its own.
Will all of my pages need to be php or is there a way to have php in html

Fou-Lu
07-17-2012, 10:37 PM
You can modify the httpd.conf or .htaccess to issue an addtype for the php interpreter.


AddType application/x-httpd-php .html

You can also use rewriting to force specific files if you want.


BTW, for your original post, $DOCUMENT_ROOT hasn't been declared anywhere. This may be a part of the $_SERVER Superglobal, but don't rely on its existence in the form of $DOCUMENT_ROOT (or even in the $_SERVER superglobal for that matter), as it will only exist in a register_global environment (which is gone as of 5.4), and disabled by default since 4.2.

Keleth
07-17-2012, 10:47 PM
Yah, by default, a server will only process files it knows to process, eg, a PHP processor will only process files ending with .php, so it won't look at ASP files or similar and try to figure them out (likely throwing a fatal error in the process). As Fou said, you can either tell your system to process HTML files through the PHP processor, or you can just rename your html files to .php. HTML is a plaintext format, so PHP won't be bothered by files with no PHP tags in them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum