phpSensei Posted September 1, 2007 Share Posted September 1, 2007 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\learn\index.php:2) in C:\wamp\www\learn\func\checkUser_Login.php on line 48 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\learn\index.php:2) in C:\wamp\www\learn\func\checkUser_Login.php on line 45 Line 45: setcookie("admin",$rec[0],time()-3600); //Delete Existing Cookies Line 48: setcookie("admin",$rec[0],time()+3600); //Assign New Cookies CODE <?php function check_adminlogin(){ // Start Function // $username = trim($_POST['username']) ; $password = trim($_POST['password']) ; // Get All Values And Assign Them To Variables // if(isset($_COOKIE['admin'])){ // Check if the user is logged in or not $message = die("You are already logged in as an admin"); // Show this mesasge if condition was TRUE } elseif(($username == "")||($password == "")){ // We check if the user has left any blank fields $message = die("Please fill in a all the fields in the form"); } else { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); //Secure the script from any sql Injections $username = strip_tags($username); $password = strip_tags($password); //Secure the script from XSS $username = trim($username); $password = trim($password); //Remove all white spaces at the end of both fields $rec=mysql_fetch_array(mysql_query("SELECT username, password FROM admin_table WHERE username = '$username' and password = '$password'"));// We make the admin table into an array // $rec2=mysql_fetch_array(mysql_query("SELECT * FROM admin_table")); // Loop through all our database coloumns if($rec2['username'] != $username){ // We check if the username exists in our database $message = die("No Such Username"); } elseif(($rec[0]==$username)&&($rec[1]==$password)){ // We validate both username and password, to see if we have a match setcookie("admin",$rec[0],time()-3600); //Delete Existing Cookies setcookie("admin",$rec[0],time()+3600); //Assign New Cookies echo "Welcome " . $username; // Print Welcome Message } else { die("Login Faild"); } } // End Condition // } // End Function // ?> Quote Link to comment https://forums.phpfreaks.com/topic/67523-solved-login-script-error/ Share on other sites More sharing options...
Fadion Posted September 1, 2007 Share Posted September 1, 2007 setcookie() must be called before any output to the browser, u should know that. See if there is any html or echo before using your function. Quote Link to comment https://forums.phpfreaks.com/topic/67523-solved-login-script-error/#findComment-339045 Share on other sites More sharing options...
phpSensei Posted September 1, 2007 Author Share Posted September 1, 2007 sorry dude, please try reading my post now... it was very messy. Quote Link to comment https://forums.phpfreaks.com/topic/67523-solved-login-script-error/#findComment-339046 Share on other sites More sharing options...
phpSensei Posted September 1, 2007 Author Share Posted September 1, 2007 OH, I fixed it. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/67523-solved-login-script-error/#findComment-339047 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.