deemurphy Posted March 24, 2009 Share Posted March 24, 2009 I am using the following code which calls has two header staements: <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Brain-Host Login</title> <link href="style.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="favicon.ico"> <link rel="icon" type="image/gif" href="favicon.gif"> </head> <body link="#FF0000" vlink="#FF0000" alink="#FFFFFF"> <font color="#FFFFFF"> <div id="topPan"> <a href="index.html"><img src="images/BrainLogo.jpg" title="Brain-Host" alt="Brain-Host" width="219" height="58" border="0" class="logo"/></a> <div id="topimagePan"><img src="images/blank.gif" alt="" /></div> <div id="topimagePan"><img src="images/blank.gif" alt="" /></div> <ul> <li class="home">home</li> <li><a href="about.html">about us</a></li> <li><a href="forums.html">forums</a>| </li> <li><a href="essay.php">essay uploads</li> <li><a href="#">purchase</a>| </li> <li><a href="contact.html">contact</a></li> </ul> </div> <?php include 'dbc.php'; $user_email = mysql_real_escape_string($_POST['email']); if ($_POST['Submit']=='Login') { $md5pass = md5($_POST['pwd']); $sql = "SELECT id,user_email FROM users WHERE user_email = '$user_email' AND user_pwd = '$md5pass' AND user_activated='1'"; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); if ( $num != 0 ) { // A matching row was found - the user is authenticated. session_start(); list($user_id,$user_email) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $user_email; if (isset($_GET['ret']) && !empty($_GET['ret'])) { header("Location: $_GET[ret]"); } else { header("Location: myaccount.php"); } //echo "Logged in..."; exit(); } header("Location: login.php?msg=Invalid Login"); //echo "Error:"; exit(); } ?> <link href="loginstyles.css" rel="stylesheet" type="text/css"> <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?> <p> </p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#590000" class="mnuheader" > <div align="center"><font size="5"><strong>Login Members</strong></font></div></td> </tr> <tr> <td bgcolor="#590000" class="mnubody"><form name="form1" method="post" action=""> <p> </p> <p align="center">Your Email <input name="email" type="text" id="email"> </p> <p align="center"> Password: <input name="pwd" type="password" id="pwd"> </p> <p align="center"> <input type="submit" name="Submit" value="Login"> </p> <p align="center"><a href="register.php">Register</a> | <a href="forgot.php">Forgot</a></p> </form></td> </tr> </table> </div> <div id="bodyBottomPan"> <div id="BottomLeftPan"> </div> <div id="BottomMiddlePan"> <p> </p> <p class="more"></p> </div> </div> <div id="footerPan"> <ul> <li><a href="index.html">home </a>| </li> <li><a href="about.html">about us</a>| </li> <li><a href="forums.html">forums</a>| </li> <li><a href="essay.php">essay uploads</a>| </li> <li><a href="#">purchase</a>| </li> <li><a href="contact.html">contact</a></li> </ul> <p class="copyright">©brain-host. all right reserved.</p> <div id="footerPanhtml"><a href="http://validator.w3.org/check?uri=referer" target="_blank">HTML</a></div> <div id="footerPancss"><a href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank">CSS</a></div> <ul class="templateworld"> <li>design by:</li> <li><a href="http://ladydee.net23.net/" target="_blank">LadyDee</a></li> </ul> </div> </font> </body> </html> I have already checked and thtere is no white space in the code. I am using code from the book PHP and Web Development and getting the above error. Is there another way to specify the header location? what can be done for this kind of problem? Why would a book tell you to use code that can cause an error? Thank you LadyDee Quote Link to comment https://forums.phpfreaks.com/topic/150867-how-to-fix-%E2%80%9Ccannot-modify-header-information-headers-already-sent%E2%80%9D-error-in/ Share on other sites More sharing options...
Mark Baker Posted March 24, 2009 Share Posted March 24, 2009 You're sending half the HTML code (not just white space) before your php block with its header statements, so of course the headers have already been sent Quote Link to comment https://forums.phpfreaks.com/topic/150867-how-to-fix-%E2%80%9Ccannot-modify-header-information-headers-already-sent%E2%80%9D-error-in/#findComment-792539 Share on other sites More sharing options...
deemurphy Posted March 24, 2009 Author Share Posted March 24, 2009 One of the things I did was change that and when I did I get invalid login: <?php ob_start(); include 'dbc.php'; $user_email = mysql_real_escape_string($_POST['email']); if ($_POST['Submit']=='Login') { $md5pass = md5($_POST['pwd']); $sql = "SELECT id,user_email FROM users WHERE user_email = '$user_email' AND user_pwd = '$md5pass' AND user_activated='1'"; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); if ( $num != 0 ) { // A matching row was found - the user is authenticated. session_start(); list($user_id,$user_email) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $user_email; if (isset($_GET['ret']) && !empty($_GET['ret'])) { header("Location: $_GET[ret]"); // redirect } else { header("Location: myaccount.php"); } //echo "Logged in..."; exit(); } header("Location: login.php?msg=Invalid Login"); //echo "Error:"; exit(); } ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Brain-Host Login</title> <link href="style.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="favicon.ico"> <link rel="icon" type="image/gif" href="favicon.gif"> </head> <body link="#FF0000" vlink="#FF0000" alink="#FFFFFF"> <font color="#FFFFFF"> <div id="topPan"> <a href="index.html"><img src="images/BrainLogo.jpg" title="Brain-Host" alt="Brain-Host" width="219" height="58" border="0" class="logo"/></a> <div id="topimagePan"><img src="images/blank.gif" alt="" /></div> <div id="topimagePan"><img src="images/blank.gif" alt="" /></div> <ul> <li class="home">home</li> <li><a href="about.html">about us</a></li> <li><a href="forums.html">forums</a>| </li> <li><a href="essay.php">essay uploads</li> <li><a href="#">purchase</a>| </li> <li><a href="contact.html">contact</a></li> </ul> </div> <link href="loginstyles.css" rel="stylesheet" type="text/css"> <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?> <p> </p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#590000" class="mnuheader" > <div align="center"><font size="5"><strong>Login Members</strong></font></div></td> </tr> <tr> <td bgcolor="#590000" class="mnubody"><form name="form1" method="post" action=""> <p> </p> <p align="center">Your Email <input name="email" type="text" id="email"> </p> <p align="center"> Password: <input name="pwd" type="password" id="pwd"> </p> <p align="center"> <input type="submit" name="Submit" value="Login"> </p> <p align="center"><a href="register.php">Register</a> | <a href="forgot.php">Forgot</a></p> </form></td> </tr> </table> </div> <div id="bodyBottomPan"> <div id="BottomLeftPan"> </div> <div id="BottomMiddlePan"> <p> </p> <p class="more"></p> </div> </div> <div id="footerPan"> <ul> <li><a href="index.html">home </a>| </li> <li><a href="about.html">about us</a>| </li> <li><a href="forums.html">forums</a>| </li> <li><a href="essay.php">essay uploads</a>| </li> <li><a href="#">purchase</a>| </li> <li><a href="contact.html">contact</a></li> </ul> <p class="copyright">©brain-host. all right reserved.</p> <div id="footerPanhtml"><a href="http://validator.w3.org/check?uri=referer" target="_blank">HTML</a></div> <div id="footerPancss"><a href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank">CSS</a></div> <ul class="templateworld"> <li>design by:</li> <li><a href="http://ladydee.net23.net/" target="_blank">LadyDee</a></li> </ul> </div> </font> </body> </html> I checked the database and my user id and password and email address is there. Thanks LadyDee Quote Link to comment https://forums.phpfreaks.com/topic/150867-how-to-fix-%E2%80%9Ccannot-modify-header-information-headers-already-sent%E2%80%9D-error-in/#findComment-792555 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.