Darn it., PHP help, please |
Darn it., PHP help, please |
Jan 13 2010, 11:09 PM
Post
#1
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 |
Alright, so I'm doing some stuff for a new project of mine and this project includes a member login system and all. I have a lot of stuff set up and logging in was fine, but for some strange reason, now that I try to login, the coding sends me to the activation page. The problem is, my account is already activated.
Here's the file that handles the login process, login.php: CODE <?php require ('../includes/functions.php'); url(); // Set parameters $username = $_POST['username']; $password = $_POST['password']; $safe_password = md5($password); $remember = $_POST['remember']; $database['server'] = 'localhost'; $database['username'] = 'username'; $database['password'] = 'password'; $database['name'] = 'database'; // Protect against MySQL Injection $username = stripslashes($username); $password = stripslashes($password); // Connect to MySQL Database mysql_connect($database['server'], $database['username'], $database['password']); mysql_select_db($database['name']); // See if user is valid function valid_user() { global $username, $password, $safe_password; if (mysql_num_rows(mysql_query("SELECT ID FROM users WHERE username = '$username' AND password = '$password' AND safe_password = '$safe_password'")) > 0) return true; } // Log in the user if (count($_POST) > 0) { $grab_id = mysql_query("SELECT ID FROM users WHERE username = '$username' AND password = '$password' AND safe_password = '$safe_password'"); $id = mysql_fetch_row($grab_id); if (!valid_user()) { header ('Location: ' . root . '/login?error=invalid'); } else if (valid_user() && activated()) { if ($remember) setcookie('hyfb_user', $username, time() + 31556926, '/'); else { setcookie ('hyfb_user', $username, 0, '/'); setcookie ('hyfb_id', $id[0], 0, '/'); } header ('Location: ' . root . '/account/dashboard'); } else { header ('Location: ' . root . '/account/activate'); } } else { header ('Location: ' . root . '/login?error=invalid'); } ?> And here's the function to check if a user is activated, activated(): CODE function activated() { $id = $_COOKIE['hyfb_id']; $username = $_COOKIE['hyfb_user']; $database['server'] = 'localhost'; $database['username'] = 'username'; $database['password'] = 'password'; $database['name'] = 'database'; $connection = mysql_connect($database['server'], $database['username'], $database['password']); mysql_select_db($database['name'], $connection); $activation_find = mysql_query("SELECT activation_key FROM users WHERE ID = '$id' AND username = '$username'"); $activation_key = mysql_fetch_row($activation_find); $status_find = mysql_query("SELECT status FROM users WHERE ID = '$id' AND username = '$username'"); $status = mysql_fetch_row($status_find); if ($activation_key[0] == '' && $status[0] == 'verified') return true; mysql_close($connection); } Okay, so, the weird thing is, if you look in the activated() function where it says: CODE if ($activation_key[0] == '' && $status[0] == 'verified') return true; it's telling me that my account is activated, yet if I go into phpMyAdmin, I see that my "activation_key" field is " " (or empty, as intended) and my "status" field is "verified". So, I'm wondering if it could be login.php file, specifically around the part where it's setting the cookies and everything. Help? |
|
|
|
![]() |
Apr 2 2010, 01:00 PM
Post
#2
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 8,629 Joined: Jan 2007 Member No: 498,468 |
Topic Closed, and Moved to Resolved Topics. Please PM a moderator if you would like this reopened.
|
|
|
|
Mikeplyts Darn it. Jan 13 2010, 11:09 PM
mipadi QUOTE(Mikeplyts @ Jan 13 2010, 11:09 PM) ... Jan 14 2010, 12:01 AM
Mikeplyts QUOTE(mipadi @ Jan 14 2010, 02:01 AM) Cou... Jan 14 2010, 12:48 AM![]() ![]() |