Jump to content

Header Already Sent..


KYKK

Recommended Posts

I have a index.php that have a header for the CSS, title... and my pages areindex.php?page=loginindex.php?page=registerindex.php?page=pages...something like that, and I did require_once 'other php doc' for the main content of the website, so it like a HTML frame, but with php get page for index.php?page=login in the URLbut it say header already sent because i have a header in index.php and the doc i require_once... but I need both header how can i do that?

Link to comment
Share on other sites

I have a header for my index

<?php  session_start();?><!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"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>-=KS=-</title><meta name="keywords" content="" /><meta name="description" content="" /><link href="star.css" rel="stylesheet" type="text/css" media="screen" /><script type="text/javascript">            da = [31,28,31,30,31,30,31,31,30,31,30,31];            function set_days () {                var d;                var date;                var opt_str = "";                var m = Months.options[Months.selectedIndex].value;                var y = Years.options[Years.selectedIndex].value;                if (m != 1) {                    d = da[m];                } else {                    date = new Date("February 29, " + y);                    d = date.getMonth() == 1 ? 29: 28; // IT'S A LEAP YEAR                }                empty_select (Days);                for (var i = 1; i <= d; i++) {                    j = i.toString();                    insertOption (Days, j, j)                }            }            function insertOption (s, t, v) {                var y = document.createElement('option');                y.text = t;                y.value = v;                try {                    s.add (y, null); // standards compliant                } catch (ex) {                    s.add (y); // IE only                }            }            function empty_select (s) {                while (s.length > 0) {                    s.remove(s.length-1);                }            }            function init () {                Months = document.getElementById("months");                Years = document.getElementById("years");                Days = document.getElementById("days");                Months.onchange = set_days;                Years.onchange = set_days;            }            window.onload = init;        </script></head><body><div id="logo">	<h1><a href="#">-=KS=-</a></h1>	<h2>-=KS=-</h2></div><div id="menu">	<ul>		<li><a href="index.php">Homepage</a></li>		<li><a href="#">Products</a></li>		<li><a href="#">Services</a></li>		<li><a href="#">About Us</a></li>		<li><a href="#">Contact Us</a></li>	</ul></div><hr /><div id="page">	<div id="sidebar">		<ul>			<li>				<h2>Categories</h2>				<ul><?php if (isset($_SESSION['user_id'])){ ?>					<li><a href="index.php?page=logout" title="Logout">Logout</a></li>					<li><a href="index.php?page=formindex" title="update index page">To update form for index</a></li>					<li><a href="index.php?page=updateblog" title="updateblog">updateblog</a></li>				    <?php 			        }                    else                    { ?>				    <li><a href="index.php?page=login" title="Login">login</a></li>					<li><a href="index.php?page=register" title="register">register</a></li>			        <?php                    }                    ?>				</ul>			</li>		</ul>		<div style="clear: both; height: 40px;"> </div>	</div>	<!-- end #sidebar -->		<div id="content">		<div class="post">			<h2 class="title"><a href="#">Welcome to Sitename.com!</a></h2>			<div class="entry">				<p><?phpif ($_GET["page"]=="login"){require_once 'login.php';}if ($_GET["page"]=="logout"){require_once 'logout.php';} if ($_GET["page"]=="register"){require_once 'register.php';}if ($_GET["page"]=="thankyou"){require_once 'thankyou.php';}if ($_GET["page"]=="updateblog"){require_once 'updateblog.php';}if ($_GET["page"]=="updateindex"){require_once 'updateindex.php';}if ($_GET["page"]=="formindex"){require_once 'formindex.php';}if ($_GET["page"]==""){require_once 'indexcontent.php';}if ($_GET["page"]=="blog"){require_once 'blog.php';}?></p>			</div>		</div>		<div class="post">			<div class="entry">				<p></p>			</div>		</div>	</div>	<!-- end #content -->	<div style="clear: both;"> </div></div><!-- end #page --><hr /><div id="footer">	<p>(c) 2009 [url="http://ksclans.co.cc"]http://ksclans.co.cc[/url]. Design by <a href="http://www.ksclans.co.cc/">-=KS=- Clan</a>.</p></div></body></html>

and i have

<?phprequire_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'login'){  $email = $_POST['email'];  $password = $_POST['password'];  if (trim($email) == '' || trim($password) == '')    $error_string .= 'Please enter your email address and password.<br>';  else  {    $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");    if (!($row = mysql_fetch_assoc($result)))      $error_string .= 'The email address was not found.<br>';    elseif ($row['password'] != sha1($password))      $error_string .= 'The password did not match.<br>';    else    {      $_SESSION['user_id'] = $row['id'];      $_SESSION['user_name'] = $row['name'];      $_SESSION['user_email'] = $row['email'];	  echo 'login success';	  header('Location: [url="http://www.yoursite.com/new_page.html'%3b%29;"]http://www.yoursite.com/new_page.html');[/url]      exit();    }  }}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>    <div class="error_text"><?php echo $error_string; ?></div>    <form action="index.php?page=login" method="post">    <input type="hidden" name="page_mode" value="login">    <div class="left_box">Email address</div>    <div class="right_box"><input type="text" name="email" size="30" maxlength="255" value="<?php if (isset($email)) echo $email; ?>"></div>    <div class="left_box">Password</div>    <div class="right_box"><input type="password" name="password" size="30"></div>    <div class="left_box"> </div>    <div class="right_box"><input type="submit" value="Log In" size="30"></div>    </form>

Link to comment
Share on other sites

The problem in ur code is:echo 'login success';header('Location: http://www.yoursite.com/new_page.html');sending a Location header means the browser will redirect to that page right away, so echo-ing something before it doesnt have any usethe reason it doesnt work is that http headers like Location only can be sent when theres no output yet, but in ur case there is the output 'login success'

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...