brmcdani Posted May 18, 2010 Share Posted May 18, 2010 I am trying to create a login for my webstie but I keep getting the following errors: Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /home/mcdtech1/public_html/lubbockwebpro.com/checklogin.php:1) in /home/mcdtech1/public_html/lubbockwebpro.com/checklogin.php on line 26 Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/mcdtech1/public_html/lubbockwebpro.com/checklogin.php:1) in /home/mcdtech1/public_html/lubbockwebpro.com/checklogin.php on line 26 Warning: Cannot modify header information - headers already sent by (output started at /home/mcdtech1/public_html/lubbockwebpro.com/checklogin.php:1) in /home/mcdtech1/public_html/lubbockwebpro.com/checklogin.php on line 28 I have looked at the lines it points out and am still having trouble here is my code: <?php ob_start(); $host="localhost"; // Host name $username="mcdtech1"; // Mysql username $password="l0608448533"; // Mysql password $db_name="mcdtech1_lakeAlanH"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Any help would be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/202114-login-error/ Share on other sites More sharing options...
CodeMaster Posted May 18, 2010 Share Posted May 18, 2010 You start output buffering at line 2. Why? That might be the problem. You cannot do header("location... while output buffering is on. So I suppose you have a good reason for output buffering, but if not, you might just want to remove that. <?php $host="localhost"; // Host name $username="mcdtech1"; // Mysql username $password="l0608448533"; // Mysql password $db_name="mcdtech1_lakeAlanH"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { ob_start(); echo "Wrong Username or Password"; ob_end_flush(); } ?> Link to comment https://forums.phpfreaks.com/topic/202114-login-error/#findComment-1059891 Share on other sites More sharing options...
CodeMaster Posted May 18, 2010 Share Posted May 18, 2010 {removed} Link to comment https://forums.phpfreaks.com/topic/202114-login-error/#findComment-1059892 Share on other sites More sharing options...
brmcdani Posted May 19, 2010 Author Share Posted May 19, 2010 Thanks for the reply, where does the {remove} go??? On the very bottom? I made the changes and noticed the Remove on the post after. Link to comment https://forums.phpfreaks.com/topic/202114-login-error/#findComment-1060353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.