papillonstudios Posted November 5, 2011 Share Posted November 5, 2011 I am having a problem with my login page when I set cookies I get this error. Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 66 Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 67 Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 68 Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in loginform.php on line 72 I do have ob_start() at the beginning and ob_flush() and the end but i still get the error <?php include('config.php'); ob_start(); @session_start(); if (!isset($_POST['login'])) { ?> <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <fieldset> <legend>Login</legend> <table> <tr> <td>Email </td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Password </td> <td><input type="password" name="password" /></td> </tr> <tr> <td><input type="submit" name="login" value="Login" /></td> </tr> <tr> <td><a href="<?=$siteurl?>/register.php">Register</a></td> </tr> </table> </fieldset> </form> <?php } else { //Declare some variables $email = secure($_POST['email']); $password = secure($_POST['password']); //Check if the form is filled out if (!$email || !$password) { echo 'Please fill out the form completely'; echo '<a href="'. $siteurl .'/login.php">Go Back</a>'; } else { $user = mysql_query("SELECT * FROM `users` WHERE email = '$email'"); if (! mysql_num_rows($user)) { echo 'That user doe not exist'; } else { //Encrypt the password $encpass = sha1($password . $salt); //Find the user $superquery = mysql_query("SELECT * FROM `users` WHERE email = '$email' AND password = '$encpass'"); if (mysql_num_rows($superquery) == 1) { //If the user is found, set the cookies setcookie("username", $email, 0); setcookie("password", $encpass, 0); setcookie("is_logged_in", true, 0); //send the user to the home page header("Location: " . $siteurl . "members.php"); } else { echo 'Password was incorrect. Please try again.'; } } } } ob_flush(); ?> what am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/ Share on other sites More sharing options...
trq Posted November 5, 2011 Share Posted November 5, 2011 Can you post your code in a readable format? Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285156 Share on other sites More sharing options...
papillonstudios Posted November 5, 2011 Author Share Posted November 5, 2011 <?php include('config.php'); ob_start(); @session_start(); if (!isset($_POST['login'])) { ?> <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <fieldset> <legend>Login</legend> <table> <tr> <td>Email </td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Password </td> <td><input type="password" name="password" /></td> </tr> <tr> <td><input type="submit" name="login" value="Login" /></td> </tr> <tr> <td><a href="<?=$siteurl?>/register.php">Register</a></td> </tr> </table> </fieldset> </form> <?php } else { //Declare some variables $email = secure($_POST['email']); $password = secure($_POST['password']); //Check if the form is filled out if (!$email || !$password) { echo 'Please fill out the form completely'; echo '<a href="'. $siteurl .'/login.php">Go Back</a>'; } else { $user = mysql_query("SELECT * FROM `users` WHERE email = '$email'"); if (! mysql_num_rows($user)) { echo 'That user doe not exist'; } else { //Encrypt the password $encpass = sha1($password . $salt); //Find the user $superquery = mysql_query("SELECT * FROM `users` WHERE email = '$email' AND password = '$encpass'"); if (mysql_num_rows($superquery) == 1) { //If the user is found, set the cookies setcookie("username", $email, 0); setcookie("password", $encpass, 0); setcookie("is_logged_in", true, 0); //send the user to the home page header("Location: " . $siteurl . "members.php"); } else { echo 'Password was incorrect. Please try again.'; } } } } ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285166 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2011 Share Posted November 5, 2011 So, where does login.php, the place where the error message states the output is occurring at, get used in that? Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285167 Share on other sites More sharing options...
papillonstudios Posted November 5, 2011 Author Share Posted November 5, 2011 What I have is login.php and loginform.php login.php holds the full login page and loginpage.php hold all functionality and display of the form Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285168 Share on other sites More sharing options...
papillonstudios Posted November 5, 2011 Author Share Posted November 5, 2011 the loginform.php is included in the login.php file Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285172 Share on other sites More sharing options...
trq Posted November 5, 2011 Share Posted November 5, 2011 So login.php includes this script? And also outputs data? There is your problem. Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285173 Share on other sites More sharing options...
papillonstudios Posted November 5, 2011 Author Share Posted November 5, 2011 ok heres the code from the login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>Login</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php include('loginform.php'); ?> </body> </html> Im just testing but around the include(); I would have my template code Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285177 Share on other sites More sharing options...
trq Posted November 5, 2011 Share Posted November 5, 2011 See all the html before the call to include. That is output. You cannot have any output prior to calling session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/250487-php-warning-cannot-modify-header-information-headers-already-sent-by-output/#findComment-1285182 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.