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
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 )

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

I'm not sure what you're trying to do.

 

If $_SESSION['myusername'] is not set then it redirects to "index.php".  If it is set then it does nothing...  The other code wouldn't even be executed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.