MIR1999 Posted March 14, 2006 Share Posted March 14, 2006 Here are the error messages i get when i try to implement my session:Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\login.php:1) in c:\inetpub\wwwroot\login.php on line 2Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\login.php:1) in c:\inetpub\wwwroot\login.php on line 2wanted to redirect you but i could not do it!Here is the code i have:<?php session_start(); //Start the session, register the values and redirect. $_SESSION['first_name'] = $row[1]; $_SESSION['user_id'] = $row[0]; if(!headers_sent()){ header("Location:http://localhost/logged_in.php"); exit(); }else{ echo'wanted to redirect you but i could not do it!'; } if(isset($_POST['login'])){ $u = $_POST['Login_email']; $p = $_POST['Password']; //Connect to db. require_once ('../mysql_connect.php'); $query = "SELECT user_id, first_name FROM users WHERE email='$u' AND password='$p'"; $result=@mysql_query($query); $row=mysql_fetch_array($result,MYSQL_NUM); if($row){//A match was made }else{//No match was made echo '<p>The email and password entered do not match those on file.</p>'; } mysql_close(); }else{ ?><!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=encoding"/> <title>Login</title> <script type="text/javascript" language="Javascript"> <!--//Validate the textfields function CheckLogData() { var problem2 = 'No'; if (document.login.Login_Name.value.length<=0) { alert ("Enter your UserName."); document.login.Login_Name.value = "*** UserName"; document.login.Login_Name.focus(); problem2 = 'Yes'; } if (document.login.Password.value.length<=0) { alert ("Enter your Password."); document.login.Password.value = "*** Password"; document.login.Password.focus(); problem2 = 'Yes'; } if (problem2 == 'No') { return true; } else { return false; } } //--> </script> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="return CheckLogData()"> <fieldset><legend> Enter your email address and password in the boxes below:</legend> <p align="left"><b>Email :</b> <input type="text" name="Login_email" size="30"></p> <p align="left"><b>Password :</b><input type="text" name="Password" size="20"></p> <p align="left"><input type="submit" name="login" value="LOGIN"></p> </form> </body> <?php } ?></html>Any ideas why its gone pear shaped? I accept that the code is probably completely wrong. Let me have it, don't hold back!! Quote Link to comment https://forums.phpfreaks.com/topic/4883-headersession-snag-have-read-threads-above-but-still-stuck/ Share on other sites More sharing options...
wildteen88 Posted March 14, 2006 Share Posted March 14, 2006 The error message is telling me that you have something being outputted to browser on line 1 in login.phpNow do you have any spaces before the [b]<?php[/b] tag also are you using notepad? If you are using notepade make sure you save file encoding to [b]ANSI[/b] and not [i]UFT-8[/i] or anything else otherwise somehidden chars get added to your file and so your get the headers already sent error message. Quote Link to comment https://forums.phpfreaks.com/topic/4883-headersession-snag-have-read-threads-above-but-still-stuck/#findComment-17303 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.