MissPurr Posted January 8, 2009 Share Posted January 8, 2009 I have a basic login that was working just fine on my local WAMPP server, and now I moved it over to my host and the login is throwing errors. It's the same version of PHP, and Mysql so that isn't the problem. Errors: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/qwo/bon-temps/index.php:3) in /home/qwo/bon-temps/login.php on line 19 Warning: Cannot modify header information - headers already sent by (output started at /home/qwo/bon-temps/index.php:3) in /home/qwo/bon-temps/login.php on line 31 Line 19: session_start(); Line 31: header("Location: myaccount.php"); Code: <?php include 'dbc.php'; $user_email = mysql_real_escape_string($_POST['email']); if ($_POST['Submit']=='Login') { $md5pass = md5($_POST['pwd']); $sql = "SELECT username,email FROM players WHERE email = '$user_email' AND password = '$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($md5pass,$user_email) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $user_email; $_SESSION['pname']= $row['username']; 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="styles.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="#d5e8f9" class="mnuheader" > <div align="center"><font size="5"><strong>Login Members</strong></font></div></td> </tr> <tr> <td bgcolor="#e5ecf9" 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> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted January 8, 2009 Share Posted January 8, 2009 you need to exit your headers <?php include 'dbc.php'; $user_email = mysql_real_escape_string($_POST['email']); if ($_POST['Submit']=='Login') { $md5pass = md5($_POST['pwd']); $sql = "SELECT username,email FROM players WHERE email = '$user_email' AND password = '$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($md5pass,$user_email) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $user_email; $_SESSION['pname']= $row['username']; if (isset($_GET['ret']) && !empty($_GET['ret'])) { header("Location: $_GET[ret]"); exit(); } else { header("Location: myaccount.php"); exit(); } //echo "Logged in..."; exit(); } header("Location: login.php?msg=Invalid Login"); //echo "Error:"; exit(); } ?> <link href="styles.css" rel="stylesheet" type="text/css"> <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted January 8, 2009 Share Posted January 8, 2009 It's /home/qwo/bon-temps/index.php:3 that we need to see. If index.php is producing output, then you must put session_start() before that output. It's a good idea to put session_start() at the very top of your script. Quote Link to comment Share on other sites More sharing options...
MissPurr Posted January 8, 2009 Author Share Posted January 8, 2009 Index.php <html> <body> <?php include ('login.php'); ?> <p /><p /> <a href="register.php">Register if you are not a member</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 8, 2009 Share Posted January 8, 2009 The reason your code worked on your local development system is because the output_buffering setting is ON in php.ini. To save time, I recommend that you turn this setting off (stop and start your web server to get any changes made to php.ini to take effect) and get your code working without errors on your development system, then move your code to your live server. The error is saying where your code is sending content to the browser that is preventing the headers from working. All headers must be sent before a single character is sent to the browser. Quote Link to comment Share on other sites More sharing options...
btherl Posted January 8, 2009 Share Posted January 8, 2009 This should fix it: <?php session_start(); ?><html> <body> <?php include ('login.php'); ?> <p /><p /> <a href="register.php">Register if you are not a member</a> </body> </html> Even that html tag at the start is enough to interfere with sessions, so you need to start them first. Quote Link to comment 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.