2013-07-17 2 views
0

세션이 10 분 내에 만료 된 후 index.php에서 자동으로 로그 아웃하려고합니다. 도와주세요?제한된 시간 후에 PHP 세션이 만료됩니다.

나는 이미이 있습니다

//this is login.php 
//register the session for user and password 
session_register("userName"); 
session_register("password"); 
if($userType=="Web_User"){ 
header("location:index.php?"); 
} 

//index.php 
//check session start or not 
    <?php 
if (!isset($_SESSION['start_time'])) 
{ 
    $str_time = time(); 
    $_SESSION['start_time'] = $str_time; 
} 
echo $_SESSION['start_time']; 

//here I want to expired if user inactive for 10 minutes and redirect to the login.php 

?> 

답변

0

제가

유래
 <script> 
var timer = 0; 
function set_interval() { 
timer = setInterval("auto_logout()", 600000); 
// set to 10 minutes 
} 

function reset_interval() { 
//resets the timer. The timer is reset on each of the below events: 
// 1. mousemove 2. mouseclick 3. key press 4. scroliing 
//first step: clear the existing timer 

if (timer != 0) { 
clearInterval(timer); 
timer = 0; 
// second step: implement the timer again 
timer = setInterval("auto_logout()", 600000); 
// completed the reset of the timer 
} 
} 

function auto_logout() { 
// this function will redirect the user to the logout script 
window.location = "logout.php"; 
} 
</script> 

및 본문 태그이 발견

onLoad="set_interval();" onmousemove="reset_interval();" onclick="reset_interval();" onkeypress="reset_interval();" onscroll="reset_interval();" 
+0

이것은 좋은 작업 스크립트입니다. 방금 사용했지만 세션을 수행하는 방법을 시도 할 것입니다. – sam

+1

세션이 시작되고 로그 아웃 페이지에서 세션을 삭제할 수있는 인덱스 페이지에서 위 코드를 사용하십시오. 인덱스 페이지로 다시로드하십시오. –

0

당신은이 같은 php session timeout 또는 하드 코드를에서 설정할 수 있습니다.

는 사용자가 로그인 할 때이를 추가합니다. 당신은 그들이 10 분 경과 여부를 확인하려는
$_SESSION['start_time'] = strtotime("now"); 

이 추가.

if($_SESSION['start_time'] <= strtotime("-10 minutes")) 
{ 
    //Log them out. 
} 
+0

$ _SESSION [ "START_TIME"] = strtotime으로 ("현재"); 이것은 에코로 이미 시작된 세션을 보여 주지만, 두 번째 부분은 나를 위해 작동하지 않습니다. – sam

관련 문제