Dee,
So, I got a little mixed up on your code. I usually do login’s a bit different and couldn’t see the trees
for the forest… Basically, there were three problems. I put the code into a little bit more formatting
and all of a sudden they jumped out at me.
First, the easy one, whenever you use any SESSION variables, you MUST start the session near the
beginning of the page. So, I added the " session_start(); " line at the beginning. Minor point, but will
save you from wondering why those session variables are not showing up in the profile page.
The real error is simple and I am sorry I did not catch it earlier. You have the validation code and the
processing code on the same page as the form. The name of the password field is “password” and in
the Javascript’s validation code only had the name as “pass”. Also, in the working part of the PHP code,
the $_POST[’’] used “pass” also. You pull this in this format: $pass=$_POST[‘pass’], not ‘password’.
So, none of the processing was actually using the real password. I made the needed changes, mostly
for myself, but I posted the fixed code below.
I also, changed the first if to use the more standard if(isset(…)). Most programmers use that code
instead of if(variable==“somevalue”)… Just more standard.
So, please try THIS version. Hope is has been a learning tool for you! LOL… Good luck!
[php]
<?php
session_start();
if (isset($_POST['submit'])) {
ini_set('display_errors',1);
error_reporting(E_ALL);
//Connect to the database through our include
include_once "connect_to_mysql.php";
$email = $_POST['email'];
$pass = $_POST['password'];
$remember = $_POST['remember']; // Added for the remember me feature
$email = strip_tags($email);
$pass = strip_tags($pass);
$email = mysql_real_escape_string($email);
$pass = mysql_real_escape_string($pass);
$pass = md5($password);
// Make query
$sql = mysql_query("SELECT * FROM memberFiles WHERE email='$email' AND password='$pass' AND email_activated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$_SESSION['id'] = $id;
$username = $row["username"];
$_SESSION['username'] = $username;
$email = $row["email"];
$_SESSION['email'] = $email;
mysql_query("UPDATE memberFiles SET last_log_date=now() WHERE id='$id'");
} // close while
// Remember Me Section Addition... if member has chosen to be remembered in the system
if($remember == "yes"){
setcookie("idCookie", $id, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
setcookie("usernameCookie", $username, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
setcookie("emailCookie", $email, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
setcookie("passCookie", $pass, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
}
// User is logged in, now switch to the live site...
header("Location: home.php"); // This would be the next page, I used home.php as sample
} else {
echo "
"; //just to make it easier to read...
echo "Your email address or password did not match our records!";
echo "If you wish to try again click on the link below:";
echo '
Press here to return to login!';
}
}// close if post
?>
Login to your profile
Log in to your account here
Email Address: |
|
Password: |
|
|
|
|
Remember me! |
[/php]