Jump to content

will this script work?


squiblo

Recommended Posts

will the redirect and timeout parts of the script work, ive basically put two together, and i dont want to wait 20mins to see if it has worked

 

<?php
session_start();
if(isset($_SESSION['myusername'])){
  header("location:profile.php");

// 20 mins in seconds
$inactive = 1200; 

$session_life = time() - $_session['timeout'];

if($session_life > $inactive){  
header("Location: logoutpage.php");     
}
S_session['timeout']=time();
exit;
?>

Link to comment
https://forums.phpfreaks.com/topic/167276-will-this-script-work/
Share on other sites

this code:

<?php
session_start();
print_r($_SESSION);
if(!isset($_SESSION['myusername'])){
header("location:index.php");


// set timeout period in seconds
$inactive = 600;

// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive)
        { session_destroy(); header("Location: logout.php"); }
}
$_SESSION['timeout'] = time();
exit;
}
?>

 

gave:

 

Array ( [timeout] => 1248446158 )

i get

Array ( [timeout] => 1248446158 )

 

then if i refresh page i get

 

Array ()

 

refresh again to get

 

Array ( [timeout] => (different number))

 

That's because the time() function returns the current time.  Unless time itself stops, the number will always change.  And, in that circumstance, you have bigger problems than your script failing.

this is the script i have now

 

<?php
session_start();
print_r($_SESSION);
if(!isset($_SESSION['myusername'])){
header("location:index.php");


// set timeout period in seconds
$inactive = 600;

// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive)
        { session_destroy(); header("Location: logout.php"); }
}
$_SESSION['timeout'] = time();
exit;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.