Jump to content

Headers Already Sent Out


Unholy Prayer

Recommended Posts

I already checked the sticky at the top of the page but it was of no help to me.  When I try to login to my users system, I get an error message that says this:
[quote]Warning: Cannot modify header information - headers already sent by (output started at /home/dev/public_html/portal/styles/default/pageheader.tpl:3) in /home/dev/public_html/portal/login.php on line 45[/quote]

This is the "pageheader.tpl" page:
[code]
<html>
<head>
<title><?php echo "$site_name"; ?></title>
<link rel=stylesheet href="styles/default/mtech.css">
</head>
<body>
<table align="center" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="center" colspan="3" class="logorow" height="80"><?php echo "$site_name"; ?><br><font class="logodesc"><?php echo "$description"; ?></font></td>
</tr><tr>
<td align="center" class="headbar" colspan="3" width="100%"><a href="index.php">HOME</a> | <a href="forums/index.php" target="new">FORUMS</a> | <a href="support.php">SUPPORT</A></td>
</tr><tr[/code]

This is my login code:
[code]<?php

include('styles/default/pageheader.tpl');
include('styles/default/menuleft.tpl');

include ('config.php');

if (empty($online['id'])){

if ($_POST['Login']) {

$user = clean($_POST['username']);
$pass = clean($_POST['password']);

if (!$user | !$pass){

echo 'You left a field empty. <a href="'.$_SERVER['REQUEST_URI'].'">Back</a>.';
}
else {

$pass = md5($pass);



$query = "SELECT * FROM `users` WHERE username = '$user' AND password = '$pass'";
$query = mysql_query($query);

if (mysql_num_rows($query) == 1){

$expire = time() + (7*86400);

setcookie("username", $user, $expire);

setcookie("password", $pass, $expire);                                         

echo "<td align='center'Success, you have been logged in!<br />";
echo "<a href='userpanel.php'>Control Panel</a><br><a href='index.php'>Index</a>";

}
else {

echo 'Incorrect username and password. <a href="'.$_SERVER['REQUEST_URI'].'">Back</a>.';
}

}

}
else {
?>
<td align='center'><table align='center' cellspacing='1' cellpadding='1' class='table'>
<tr>
<form method="post" action="<?=$_SERVER['REQUEST_URI']?>">
<td align='center' colspan='2' class='menuhead'>Member Login</td>
</tr><tr>
<td align='right' class='inputrow'>Username:</td>
<td align='left' class='inputrow'><input class='input' name="username" type="text" id="username"></td>
</tr><tr>
<td align='right' class='inputrow'>Password:</td>
<td align='left' class='inputrow'><input name="password" type="password" id="password"></td>
</tr><tr>
<td align='center' class='inputrow' colspan='2'><input name="Login" type="submit" id="Login" value="Login"></td>
</tr>
</form>
</table>
<?
}

}
else {

echo "<td align='center'>You are already logged in!</td>";

}

include('styles/default/menuright.tpl');
include('styles/default/pagefooter.tpl');
?> [/code]

If someone could please help me, that would be great.
Link to comment
Share on other sites

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.

You've already started output before the call to setcookie()

Link to comment
Share on other sites

[quote author=jsladek link=topic=118104.msg482263#msg482263 date=1165783460]
You should set the cookies between the head tags.[code]
<head>
set cookies in here
</head>
[/code]
[/quote]

Sorry jsladek but that has nothing to do with headers allready being sent. Maybe you should read the sticky aswell.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.