graham23s Posted May 15, 2007 Share Posted May 15, 2007 Hi Guys, i normally use this script for my check login: <?php include("includes/db_connection.php"); // the includes...////////////////////////////////////////////////////////////////// include("includes/header.php"); include("includes/navbar.php"); // For register_global on PHP settings/////////////////////////////////////////////// $username = strtolower($_POST['username']); $password = strtolower($_POST['password']); // Check for empty fields if (empty($username) || empty($password)) { echo "<center><br /><font color=\"red\"><p>Sorry Please Fill In All The Required Fields <a href=\"login.php\">Try Again</a></p></font></center>"; exit; } // Match the user in the database...///////////////////////////////////////////////// $query_1 = "SELECT username,password FROM `membership` WHERE `username`='$username' AND `password`='$password'"; $result_1 = mysql_query($query_1) or die (mysql_error()); $is_greater_than_1 = mysql_num_rows($result_1); // was there a user found?...//////////////////////////////////////////////////////// if($is_greater_than_1 != 1) { echo "<p>Sorry, You Have Typed In The Wrong Username And Password Combination.</p>"; } else { // User is logged in so Let's give him a cookie. //////////////////////////////////// setcookie ("member",$username,time()+3600*24*30,"/"); $member = $username; // If cookie failed set a session...///////////////////////////////////////////////// $_SESSION['member'] = 'member'; // Update Login timer...///////////////////////////////////////////////////////////// $query_2 = "UPDATE `membership` SET `login`=now() WHERE `username`='$username' AND `password`='$password'"; $result_2 = mysql_query($query_2); if ($result_2) { header("Location:my_account.php"); // redirects members to a welcome member page///// }} ?> i'm getting "Warning: Cannot modify header information" error, i know it's because i have echoes in there before the header but i was wondering if there was a better way i could do this, would i be better putting the check login scrips on the same page as the login.php or would i still get errors? thank guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/51448-solved-headers-error-in-check-login-script/ Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 The reason why is because you are outputting html before you are setting cookies... or sending the header("LOCATION:") deal... and it all has to deal with the placement of these 2 lines: include("includes/header.php"); include("includes/navbar.php"); change the placement of those, and you'll be set... Quote Link to comment https://forums.phpfreaks.com/topic/51448-solved-headers-error-in-check-login-script/#findComment-253372 Share on other sites More sharing options...
graham23s Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks mate changed the location, set them in an isset before the form code. cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/51448-solved-headers-error-in-check-login-script/#findComment-253379 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.