Hey Rich
Here are a few suggestions (this is only for tips and pointers if you want 'em). You don't really need to re-validate the session user if its already set because in theory they should already be logged in. Also in the login process, I give an example to reset the session (sometimes good to do when changing to login state). And finally, use the full URL for redirect and exit out of the current running script.
PHP Code:
function check_login($username, $password, $required = 1, $redirect = 'https://www.domain.com/login.php') { if (isset($_SESSION['user']) AND isset($_SESSION['pass'])) return true; if (!empty($username) AND !empty($password)) { $username = stripslashes($username); $password = stripslashes($password); $checkq = mysql_query(" SELECT username, password FROM users WHERE username = '" . mysql_real_escape_string($username) . "' AND password = '" . md5($password) . "' LIMIT 1 "); if (mysql_num_rows($checkq) > 0) { $session_backup = $_SESSION; unset($_COOKIE[session_name()]); session_destroy(); session_start(); $_SESSION = $session_backup; unset($session_backup); $user_row = mysql_fetch_assoc($checkq); $_SESSION['user'] = $user_row['username']; $_SESSION['pass'] = $user_row['password']; unset($user_row); return true; } } if ($required == 1) { header("location: $redirect"); exit(); } return false; }
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|