0

Hi,

I have this codes:

(index.html)

<body>  
    
         <div id="wrapper">  
    
<?php include('includes/header.php'); ?> 
    
     <div id="nav"> 
    
     <a href="#">Home</a>  
     <a href="#">About</a>  
     <a href="#">Portfolio</a>  
     <a href="#">Contact</a>  
    
  </div> <!-- end #nav -->

I wonder why <?php include('includes/header.php'); ?> does not works. In other words, the codes that I have place in header.php does not appears in index.html when I run it in IE.

includes/header.php

<div id="header">  
    
     <h2>1stWebDesigner PHP Template</h2>  
    
</div>

no errors. It's just after I cut and paste the codes from index.html and move it header.php and writes: <?php include('includes/header.php'); ?> , the header disappeared.

What might be the problems ?

Thanks.

Edited by davy_yg: adding information

10
Contributors
18
Replies
20
Views
6 Years
Discussion Span
Last Post by azeem786
0

does the header.php is on the same folder with your index.html?
if your header.php is within the same folder with your index.html
remove the "includes" and this will be your code:

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

or if your header.php is not within the same folder with your index.html and located
at the folder named "includes", this should be your code:

<?php include('../includes/header.php'); ?>

enjoy codings!

0

still does not work, I wonder why?

am I writing the header.php codes correctly ?

<div id="header">  
    
     <h2>1stWebDesigner PHP Template</h2>  
    
</div>

That's the whole codes for header.php

include('../includes/header.php');

The header still does not appears.

0

Try to surround code in header.php with <?php ?> tags.

<?php
<div id="header">
     <h2>1stWebDesigner PHP Template</h2>  
</div>
?>
0

Try to close the div tag

<div id="wrapper">

or remove it.

<body>
 
 
<?php include('includes/header.php'); ?>
 
<div id="nav">
 
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Portfolio</a>
<a href="#">Contact</a>
 
</div> <!-- end #nav -->
0

This is the problem: YOU PUT PHP CODE IN HTML FILE. RENAME "INDEX.HTML" to INDEX.PHP and it should work.

0

have not yet. I tried another one:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

include('../includes/header.php'); 

?>

Test includes

</body>
</html>

This is index.html2 for experiment.

includes\header.php

<?php

<div id="header">  
    
     <h2>1stWebDesigner PHP Template</h2>  
    
</div>
  
?>

The result is:

Test includes

(The header does not appear)

0

I change index.html to index.php

The following errors appears:

Warning: include(../includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\php_template\index.php on line 29

Warning: include() [function.include]: Failed opening '../includes/header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\php_template\index.php on line 29

Warning: include(../includes/nav.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\php_template\index.php on line 31

Warning: include() [function.include]: Failed opening '../includes/nav.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\php_template\index.php on line 31

strange I have the file path correctly but the errors still appears.

1

Are you sure? There are ../ and it means from previous directory:
C:\xampp\htdocs\php_template\index.php is your file, and "includes/header.php" will be searched in previous directory (in this case in htdocs):
C:\xampp\htdocs\includes/header.php

0

do you have php installed? try a new index.php page. all you need on it is:

<?php
phpinfo();
?>
// what are your results?
0

I took off the "../" now this is another error:

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\php_template\includes\header.php on line 4

header.php


<div id="header">

<h2>1stWebDesigner PHP Template</h2>

</div>


line 4 is: <h2>1stWebDesigner PHP Template</h2>

Edited by davy_yg: deleting unnecessary info

0

phpinfo();

result:

PHP Version 5.3.5

System Windows NT XP-94F2C852C7B7 5.1 build 2600 (Windows XP Professional Service Pack 2) i586
Build Date Jan 6 2011 17:50:45
Compiler MSVC6 (Visual C++ 6.0)
Architecture x86
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--disable-isapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=D:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static"
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\xampp\php\php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,TS,VC6
PHP Extension Build API20090626,TS,VC6
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, phar
Registered Stream Socket Transports tcp, udp
Registered Stream Filters convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.*

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

0

try:

include($_SERVER['DOCUMENT_ROOT']. "includes/header.php");
// or at least echo $_SERVER['DOCUMENT_ROOT'];  
// the expected value in your case would be:
C:/xampp/htdocs/
// from ivans post, I am assuming that includes directory is right on top of htdocs if this is the case the include statement above should work.
0

Where is your index.php and header.php ? Your path looks like 'header.php' is under 'includes' folder which is the same root of the folder which contains 'index.php'.

The error says that the file does not exist in this directory. Check the path again. I'm not sure, perhaps, the 'includes' folder might be same root with 'index.php'. If then, remove '..' from include(../includes/header.php) , like this one, include(includes/header.php) Hope this help.

0

Copy the header-php file in the directory where index.html is and test wheter inclusion works by changing the include line to just

include('header.php');

. If that works than in your previous case the path was not correct.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.