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,417
  • 15
  • 73
  • 132
roun512
  • 149
  • 11
  • 2
    instead of "include" try "include once" or "require once" – Krish Aug 14 '13 at 03:03
  • Does your header have connect.php include aswell ? – Sir Aug 14 '13 at 03:11
  • @Dave , no I Posted the source code of it :) – roun512 Aug 14 '13 at 03:22
  • this is so common question, you can find answer in google. -1. – skmasq Aug 14 '13 at 03:25
  • @skmasq the point of SO is to have it all in one place.. Google is not the answer. Although SO has a search function which probably would of given the answer. – Sir Aug 14 '13 at 03:31
  • @skmasq As i wrote in the NOTE ! i didn't know on what to search exactly and i did search for include and i got this http://stackoverflow.com/questions/17958787/include-html-pages-in-a-php-file?lq=1 . – roun512 Aug 14 '13 at 07:57

2 Answers2

1

Use

include_once('header.php');

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

akatakritos
  • 9,836
  • 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