Unholy Prayer Posted December 10, 2006 Share Posted December 10, 2006 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]<?phpinclude('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 https://forums.phpfreaks.com/topic/30158-headers-already-sent-out/ Share on other sites More sharing options...
jsladek Posted December 10, 2006 Share Posted December 10, 2006 You should set the cookies between the head tags.[code]<head>set cookies in here</head>[/code] Link to comment https://forums.phpfreaks.com/topic/30158-headers-already-sent-out/#findComment-138616 Share on other sites More sharing options...
bljepp69 Posted December 10, 2006 Share Posted December 10, 2006 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 https://forums.phpfreaks.com/topic/30158-headers-already-sent-out/#findComment-138617 Share on other sites More sharing options...
trq Posted December 10, 2006 Share Posted December 10, 2006 [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 https://forums.phpfreaks.com/topic/30158-headers-already-sent-out/#findComment-138635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.