ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How to track user logged out or not in php? when user is idle?

user-image
تم إضافة السؤال من قبل qasim nawaz , Seninor Web/Software Developer , CITC COMSATS Institute of Information Technolgy Lahore
تاريخ النشر: 2015/10/08
Julfkar  Moh Umar
من قبل Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited

There are a few ways to do this. Here are a couple...

  • set a session expiry time, such that after a certain amount of time, the session expires and is no longer valid.

  • set a time flag as session data, and check if their session is still  new enough to keep them logged in each pageload.

Mostafa Mohammed Naguib
من قبل Mostafa Mohammed Naguib , Senior back-end developer , Egpay payment solution

since Php is server side, there are no way to check it unless a page reload or an ajax calland you can always save a time stamp in $_sessions or $_cookie for checking later on, and have a call in jQuery like so

 

 function CHeckLogedin(){

         $.get('checklogin.php', {}, function(returndata){

             if(returndata == 'true'){

                //user still logged in

                alert('you are still logged in');

              } else {

               //user logged out

               window.location='signin.php';

         });

}

next in checklogin.php page

do something like

<?

start_session();

$next5min = strtotime('+5 minute');

if ($_SESSION[time] < $next5min){

        echo 'true';

} else {

        echo 'false';

}

?>

and whenever user moves between pages change his $_SESSION[time] to time(), so its always updatedand in whichever page you wanna have that check do something like

setTimeout(CHeckLogedin(),);

i haven't tested this code, so it might have some bugs

 

Hope that helped,have a good day.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟