1

So Lately i was working on a website on LocalHost Using XAMPP Application.

So i created header.php with the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="description" content="A short description." />
<meta name="keywords" content="put, keywords, here" />
<title>Website Name</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="menu">
    <a class="item" href="index.php">Home</a>
    <a class="item" href="../forum/">Forums</a>
    <a class="item" href="live-chat.php">Live Chat</a>
    <a class="item" href="Login.php">Log In</a>
    <a class="item" href="Register.php">Register Now!</a>
    <div id="userbar">
    <?php
    error_reporting(E_ALL & ~E_NOTICE);
    include 'search.php';
    if($_SESSION['signed_in'])
    {
        echo 'Welcome <b>' . htmlentities($_SESSION['user_name']) . '</b>. Not you? <a class="item" href="logout.php">Log out</a>'; 
    }
    ?>
    </div>
</div>
<div id="content">

And a Login.php with this code ( Here is the 4 lines of it ) :

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

etc..... php code....

Ok so the problem is When i try to open the login.php in web browser i got the code in header.php duplication many many times like it don't end duplicating it self and if i open the source code of login.php i will got unlimited number of the code used in header.php like all the source code is header.php repeatedly.

So I'am asking you guys for help on how to fix this and what is the error ??

NOTE: Sorry if their was a thread duplication but i didn't know on what to search exactly.

If you want anymore information I'am ready.

Thanks all much appreciated

Prix
  • 19,173
  • 14
  • 69
  • 128
roun512
  • 149
  • 11

2 Answers2

1

Use

include_once('header.php');

everywhere instead. It will check to see if the file has already been included.

akatakritos
  • 9,806
  • 1
  • 23
  • 29
  • Thank you akatakritos , it did really work Much appreciated btw, this guy http://stackoverflow.com/questions/17958787/include-html-pages-in-a-php-file?rq=1 have the same problem as me but he don't know what is the problem or what is hapenning anyway thank you :) – roun512 Aug 14 '13 at 03:18
0

use require_once instead, it will load the file just once, and only if needed.

You have more info here

Community
  • 1
  • 1