gli Posted April 17, 2008 Share Posted April 17, 2008 logincheck.php file which process the login.php login form <?php require_once("session.php"); ?> <?php require_once("functions.php"); ?> <?php require_once("databasec.php"); ?> <?php $username = $_POST['username']; $password = $_POST['password']; $hashedpassword = sha1($password); $query = "SELECT *"; $query .= "FROM users "; $query .= "WHERE username = '{$username}' "; $query .= "AND hashedpassword = '{$hashedpassword}' "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if (mysql_num_rows($result_set) == 1) { $found_user = mysql_fetch_array($result_set); $_SESSION['user_id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; redirect_to("login.php"); } else { $message = "Username/password incorrect. <br /> Please make sure your caps lock key is off and try again."; echo $message; } ?> functions.php file <?php function confirm_query($result_set) { if (!$result_set) { die("Database query failed: " . mysql_error()); } } function redirect_to( $location = NULL ) { if ($location != NULL) { header("Location: {$location}"); exit; } } ?> When im trying to login it shows: Warning: Cannot modify header information - headers already sent by (output started at /home/www/jimperija.atwebpages.com/functions.php:19) in /home/www/jimperija.atwebpages.com/functions.php on line 13 where is the problem? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 17, 2008 Share Posted April 17, 2008 The problem is that you are sending white space to the browser. Anything that is outside of PHP tags will be sent to the browser as plain text. Try: <?php require_once("session.php"); require_once("functions.php"); require_once("databasec.php"); $username = $_POST['username']; $password = $_POST['password']; $hashedpassword = sha1($password); $query = "SELECT *"; $query .= "FROM users "; $query .= "WHERE username = '{$username}' "; $query .= "AND hashedpassword = '{$hashedpassword}' "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if (mysql_num_rows($result_set) == 1) { $found_user = mysql_fetch_array($result_set); $_SESSION['user_id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; redirect_to("login.php"); } else { $message = "Username/password incorrect. <br /> Please make sure your caps lock key is off and try again."; echo $message; } ?> Quote Link to comment Share on other sites More sharing options...
gli Posted April 18, 2008 Author Share Posted April 18, 2008 and... Warning: Cannot modify header information - headers already sent by (output started at /home/www/jimperija.atwebpages.com/functions.php:19) in /home/www/jimperija.atwebpages.com/functions.php on line 13 again... Quote Link to comment Share on other sites More sharing options...
haku Posted April 18, 2008 Share Posted April 18, 2008 You have sent text (which may only be a space) to the browser before your redirect statement. Find out where that text is, and remove it. Quote Link to comment Share on other sites More sharing options...
gli Posted April 18, 2008 Author Share Posted April 18, 2008 omg. thnx. but i didnt understand you for all 100%, but i deleted all spaces and now its working Quote Link to comment 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.