aftab_jii Posted February 20, 2007 Share Posted February 20, 2007 do you guys see anything missing in this code..i am unable to send the SESSION variables to the next page: <?php //ob_start(); include('files/authenticate.php'); if (isset($_POST['submit'])) { // Check if the form has been submitted. include('files/config.php'); // Connect to the database. if (empty($_POST['email'])) { // Validate the username. $email = FALSE; echo '<font color="red">You forgot to enter your username!</font><br>'; } else { $email = $_POST['email']; } if (empty($_POST['passwd'])) { // Validate the password. $password = FALSE; echo '<font color="red">You forgot to enter your password!</font><br>'; } else { $password = $_POST['passwd']; } if ($email && $password) { // If everything OK. // Query the database. $query = "SELECT user_id, access_lvl, name " . "FROM users " . "WHERE email='" . $_POST['email'] . "' " . "AND passwd=PASSWORD('" . $_POST['passwd'] . "')"; $row = mysql_query ($query); if ($row) { // A match was made. //Start the session, register the values & redirect. session_start(); $row = mysql_fetch_assoc($row); $_SESSION['user_id'] = $row['user_id']; $_SESSION['access_lvl'] = $row['access_lvl']; $_SESSION['name'] = $row['name']; //ob_end_clean(); // Delete the buffer. header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedinn.php"); //exit(); //ob_end_clean(); // Delete the buffer. } else { // No match was made. echo '<font color="red">The username and password entered do not match those on file.</font><br>'; } mysql_close(); // Close the database connection. } else { // If everything wasn OK. echo '<font color="red">Please try again.</font><br>'; } } // End of SUBMIT conditional. //ob_end_flush(); ?> <form action="login.php" method="post"> <p>E-mail address:<br> <input type="text" name="email" maxlength="255" value=""> </p> <p>Password:<br> <input type="password" name="passwd" maxlength="99"> </p> <p> <input type="submit" name="submit" value="Login"> </p> </form> <p></p> Quote Link to comment Share on other sites More sharing options...
marcus Posted February 20, 2007 Share Posted February 20, 2007 session_start(); has to be the first line of the code, if you're using ob_start(); then it'll be the second. Quote Link to comment Share on other sites More sharing options...
aftab_jii Posted February 20, 2007 Author Share Posted February 20, 2007 im not using ob_start().. ob_start() is a comment.. Quote Link to comment Share on other sites More sharing options...
tllewellyn Posted February 20, 2007 Share Posted February 20, 2007 That's true, but regardless, as mgallforever mentioned, the very first thing on the page MUST be session_start() or you will be unable to capture and pass SESSION data between pages. session_start is completely separate from using ob_start() Good luck, Trev Quote Link to comment Share on other sites More sharing options...
am_25 Posted February 20, 2007 Share Posted February 20, 2007 Is the session getting created. I had the same problem. Check you session.savepath using phpinfo(). If the folder doesnot exist create it and give write permissions. the session.savepath is in the php.ini file. One more problem which I had was using the "include" in the first line, i removed it and it worked. You can place the include file, just before u use it. But first try the session.savepath Quote Link to comment Share on other sites More sharing options...
aftab_jii Posted February 20, 2007 Author Share Posted February 20, 2007 session is being created in authenticate.php.. authenticate.php controlls the sessions and thus prevent multiple loginn 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.