mysql - how to create an automatic logout script in php -
im trying create auto logout system automatically log out of system when page inactive,i newbie , when added code login page im getting these warnings
warning: mysql_query() expects parameter 1 string, resource given in c:\xampp\htdocs\how things\admin panel\login.php on line 80 warning: mysql_num_rows() expects parameter 1 resource, null given in c:\xampp\htdocs\how things\admin panel\login.php on line 81
the code on line 80 , 81 these below respectively
if($no_rows > 0){ while($resgetadmin = mysql_fetch_assoc($rs_user))
this code added
$rs_user= mysql_query($check_login); $no_rows = mysql_num_rows($rs_user); if($no_rows > 0){ while($resgetadmin = mysql_fetch_assoc($rs_user)){ $selquery="select * login user_id=".$resgetadmin['user_id'] ." , logindate ='$current_date'"; $rgetdata= mysql_query($selquery); $num_login = getsqlnumber($selquery); if($num_login==0) { $insquery= "insert login (user_id,logintime,logindate,count) values (".$resgetadmin['user_id'].",'$current_time','$current_date',1)"; $login_user= mysql_query($insquery); $insert_id=mysql_insert_id(); $_session['logintime']=$current_time; }else{ $count = mysql_result($rgetdata,0,’count’); $count = $count+1; $updatequery= "update login set logintime='$current_time' ,logindate='$current_date' , count ='$count' user_id=".$resgetadmin['user_id'] ." , logindate='$current_date'"; $login_user= mysql_query($updatequery) or mysql_error(); $_session['logintime']=$current_time; } $_session['user_id']=$resgetadmin['user_id']; header("location: index.php"); exit; } }
this original login page before added code above
<?php if(isset($_post['submit'])){ $username = $_post['username']; $password =($_post['password']); $hash_password = md5($password); $hash_password1 = sha1($hash_password); $hash_password2 = crypt($hash_password1,"st"); $hash_password3 = hash("sha512",$hash_password2); $guess = $_post['captcha']; $real = (isset($_session['real'])) ? $_session['real'] : ""; if (empty($guess)) { die("please enter correct captcha.<br>"); } if (!empty($guess) && $guess !== $real) { die("please enter correct captcha.<br>"); } if(empty($username) or empty($password)){ echo "<p>fields empty !</p>"; } else { $check_login = mysql_query("select id, type users username='$username' , password='$hash_password3'"); if(mysql_num_rows($check_login) == 1) { $run = mysql_fetch_array($check_login); $user_id = $run['id']; $type = $run['type']; if($type == 'd'){ echo "<p> account deactivated byt site admin!</p>"; } else { $_session['user_id'] = $user_id; header('location: index.php'); } } else { echo "<p> user name or password incorrect!</p>"; } } } ?>
i pasted whole code on login page left timeout.php page,thanks in advance guys
there no need logout writing own code. each session can configured last time. can set maximum lifetime.
Comments
Post a Comment