brophi Posted October 27, 2007 Share Posted October 27, 2007 I know that there is a topic about this but it didnt help me very much. I am fairly new to php and i have no idea why my code is displaing these errors, any help would be greatly apretiated!!!! the code: <link href="style.css" rel="stylesheet" type="text/css" /> <?php include("connect.php"); $sql = mysql_query("SELECT * FROM users WHERE username='".addslashes($_POST['username'])."'") or die("username was in correct. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); if($result['password'] == sha1($_POST['password'])){ session_start(); header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['username']; header("location: protected.php"); }else{ echo "Incorrect login details please try again."; } ?> and the error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\site\login.php:2) in C:\xampp\htdocs\site\login.php on line 7 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\login.php:2) in C:\xampp\htdocs\site\login.php on line 8 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\login.php:2) in C:\xampp\htdocs\site\login.php on line 10 Thank you and im im sorry again... Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/ Share on other sites More sharing options...
darkfreaks Posted October 27, 2007 Share Posted October 27, 2007 put ob_start(); before session start Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379139 Share on other sites More sharing options...
trq Posted October 27, 2007 Share Posted October 27, 2007 session_start() cannot be called after any[/i] output has been sent to your browser. This.... <link href="style.css" rel="stylesheet" type="text/css" /> is output. Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379140 Share on other sites More sharing options...
LemonInflux Posted October 27, 2007 Share Posted October 27, 2007 I was just going to say, put it at the very top. <?php session_start(); ?> then put your css Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379141 Share on other sites More sharing options...
trq Posted October 27, 2007 Share Posted October 27, 2007 put ob_start(); before session start That is a hack. You need (or should) move your logic so as session_start() need not be called after output. Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379142 Share on other sites More sharing options...
LemonInflux Posted October 27, 2007 Share Posted October 27, 2007 Try this: <?php session_start(); echo '<link href="style.css" rel="stylesheet" type="text/css" />'; include("connect.php"); $sql = mysql_query("SELECT * FROM users WHERE username='".addslashes($_POST['username'])."'") or die("username was in correct. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); if($result['password'] == sha1($_POST['password'])){ header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['username']; header("location: protected.php"); }else{ echo "Incorrect login details please try again."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379145 Share on other sites More sharing options...
brophi Posted October 27, 2007 Author Share Posted October 27, 2007 Thanks for the quick reply! but sorry, its still not working... I did manage to get rid of some of the errors, tahnks to your help here is my code NOW: <?php session_start(); ?> <link href="style.css" rel="stylesheet" type="text/css" /> <?php include("connect.php"); $sql = mysql_query("SELECT * FROM users WHERE username='".addslashes($_POST['username'])."'") or die("username was in correct. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); if($result['password'] == sha1($_POST['password'])){ header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['username']; header("location: protected.php"); }else{ echo "Incorrect login details please try again."; } ?> And here are the errors... Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\login.php:3) in C:\xampp\htdocs\site\login.php on line 8 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\login.php:3) in C:\xampp\htdocs\site\login.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379150 Share on other sites More sharing options...
rajivgonsalves Posted October 27, 2007 Share Posted October 27, 2007 Your code should be like this <?php session_start(); include("connect.php"); $sql = mysql_query("SELECT * FROM users WHERE username='".addslashes($_POST['username'])."'") or die("username was in correct. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); if($result['password'] == sha1($_POST['password'])){ header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['username']; header("location: protected.php"); }else{ echo '<link href="style.css" rel="stylesheet" type="text/css" />' echo "Incorrect login details please try again."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379199 Share on other sites More sharing options...
brophi Posted October 28, 2007 Author Share Posted October 28, 2007 GRRR! Its still not working! i used the code above: <?php session_start(); include("connect.php"); $sql = mysql_query("SELECT * FROM users WHERE username='".addslashes($_POST['username'])."'") or die("username was in correct. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); if($result['password'] == sha1($_POST['password'])){ header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['username']; header("location: protected.php"); }else{ echo '<link href="style.css" rel="stylesheet" type="text/css" />' echo "Incorrect login details please try again."; } ?> but that didnt work: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\xampp\htdocs\site\login.php on line 12 I fixed that error: <?php session_start(); include("connect.php"); $sql = mysql_query("SELECT * FROM users WHERE username='".addslashes($_POST['username'])."'") or die("username was in correct. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); if($result['password'] == sha1($_POST['password'])){ header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['username']; header("location: protected.php"); }else{ echo "Incorrect login details please try again."; echo '<link href="style.css" rel="stylesheet" type="text/css" />'; } ?> BUT THEN I GET THIS ERROR AGAIN!! Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\connect.php:2) in C:\xampp\htdocs\site\login.php on line 7 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\connect.php:2) in C:\xampp\htdocs\site\login.php on line 9 PLEASE HELP! this is very frustrating! Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379559 Share on other sites More sharing options...
brophi Posted October 28, 2007 Author Share Posted October 28, 2007 Oh wait! thats for a different file! silly me, i will try yo fix that one! i feel so stupid EDIT! YAY I FIXED IT! thanks for all your help, its really appretiated (no sarcasm intended) Quote Link to comment https://forums.phpfreaks.com/topic/74971-solved-login-script-using-sessions-wont-work/#findComment-379560 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.