Jump to content

login.php ... cant figure out whats wrong


aftab_jii

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.