phpbiginner Posted June 11, 2011 Share Posted June 11, 2011 how you doing guys?, i just wanna ask a question, please can somebody tell me what this means, the headers already sent by .............. in simple words please, because i keep searching to know the meaning of it, and i still don't get it, i'm new to the whole php thing, so please take it easy on me, i'm not a professional yet, not even close to amateur lol. it keep telling me the samething over and over again if you want the whole thing it's down there. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\siteS\connectvas.php:9) in C:\xampp\htdocs\siteS\login.php on line 5 <?php require_once('connectvas.php'); // Start the session line 5--------> session_start(); // Clear the error message $error_msg = ""; // If the user isn't logged in, try to log them in if (!isset($_SESSION['user_id'])) { if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect('localhost', 'root', 'september14', 'testdrive11'); // Grab the user-entered log-in data $user_username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $user_password = mysqli_real_escape_string($dbc, trim($_POST['password'])); if (!empty($user_username) && !empty($user_password)) { // Look up the username and password in the database $query = "SELECT user_id, username FROM mismatch_user WHERE username = '$user_username' AND password = SHA('$user_password')"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page $row = mysqli_fetch_array($data); $_SESSION['user_id'] = $row['user_id']; $_SESSION['username'] = $row['username']; setcookie('user_id', $row['user_id'], time() + (60 * 60 * 24 * 30)); // expires in 30 days setcookie('username', $row['username'], time() + (60 * 60 * 24 * 30)); // expires in 30 days $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { // The username/password are incorrect so set an error message $error_msg = 'Sorry, you must enter a valid username and password to log in.'; } } else { // The username/password weren't entered so set an error message $error_msg = 'Sorry, you must enter your username and password to log in.'; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mismatch - Log In</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h3>Mismatch - Log In</h3> <?php // If the session var is empty, show any error message and the log-in form; otherwise confirm the log-in if (empty($_SESSION['user_id'])) { echo '<p class="error">' . $error_msg . '</p>'; ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Log In</legend> <label for="username">Username:</label> <input type="text" name="username" value="<?php if (!empty($user_username)) echo $user_username; ?>" /><br /> <label for="password">Password:</label> <input type="password" name="password" /> </fieldset> <input type="submit" value="Log In" name="submit" /> </form> <?php } else { // Confirm the successful log-in echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '.</p>'); } ?> Link to comment Share on other sites More sharing options...
trq Posted June 11, 2011 Share Posted June 11, 2011 If you had posted your question in the correct board you might have noticed the big sticky thread at the top which says; HEADER ERRORS - READ HERE BEFORE POSTING THEM. Please note, we also have code tags for using when posting code. Link to comment Share on other sites More sharing options...
Recommended Posts