mr_mind Posted December 8, 2007 Share Posted December 8, 2007 I have this code to log a user into my website: <?php if($_POST['login']) { if(verify_user(verified, $_SESSION['user_id'], $_SESSION['password'])==0) { if($_POST['login_userid'] && $_POST['login_password']) { if(mysql_connect('localhost','quinn','IOSubSys')) { if(mysql_select_db('iqlogin')) { $user_name_query = mysql_query("SELECT * FROM iql_user WHERE user_name='" . $_POST['login_userid'] . "'"); $user_name_array = mysql_fetch_array($user_name_query); $login_user_id = $user_name_array['user_id']; if(verify_user(verified, $login_user_id, $_POST['login_password'], yes)==1) { if(verify_user(active, $login_user_id, $_POST['login_password'], yes)==1) { $login_password = $_POST['login_password']; session_start(); $_SESSION['user_id'] = $login_user_id; $_SESSION['password'] = md5($login_password); $message = 'You have successfully logged in. Please wait while you are redirected.'; header("location:http://www2.iqlogin.net/index.php"); } else { $error = 'You must activate your account before you may login'; } } else { $error = 'Incorrect password or userid'; } } else { $error = 'Failed connecting to the server. Please notify an administrator with this error: ' . mysql_error(); } } else { $error = 'Failed connecting to the server. Please notify an administrator with this error: ' . mysql_error(); } } else { $error = 'You must fill in your userid and password'; } } else { $error = 'You are already logged in as ' . $_SESSION['user_id'] . '. <a href=http://www2.iqlogin.net/user/login.php?l=1>Click here</a> to logout.'; } } ?> And it sends me to http://www2.iqlogin.net/index.php as it is supposed to but the code which is supposed to tell me if i am logged in or not: <?php function verify_user($option, $user_id, $password, $md5=NULL) { if($user_id!='' && $password!='') { if($md5=='yes') { $verify_password = md5($password); } else { $verify_password = $password; } $verify_query = mysql_query("SELECT * FROM iql_user WHERE user_id='" . $user_id . "'"); if(mysql_num_rows($verify_query)>0) { $verify_array = mysql_fetch_array($verify_query); if($verify_password == $verify_array['user_password']) { switch($option) { case 'verified': return '1'; break; case 'id': return $verify_array['user_id']; break; case 'email': return $verify_array['user_email']; break; case 'password': return $verify_array['user_password']; break; case 'random': return $verify_array['user_random']; break; case 'active': return $verify_array['user_active']; break; } } else { return '0'; } } else { return '0'; } } else { return '0'; } } ?> Which i call through: if(verify_user(verified, $_SESSION['user_id'], $_SESSION['password'])==0) { Tells me that i am not logged in. so what, may i ask is the problem that i am not seeing? Quote Link to comment Share on other sites More sharing options...
Stooney Posted December 8, 2007 Share Posted December 8, 2007 you need to add session_start(); at the tops of the pages. 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.