Jump to content

Correct way of doing a PHP Timeout


j.smith1981

Recommended Posts

I was wanting to make some kind of session timeout ability, just purely out of curiosity.

 

I have tried going off my own theory, before looking at any tutorials, well have looked a bit but tried getting the jist and having a go myself the next day (anyways that being said), this code here:

 

<?php
ini_set('display_errors', 1);
session_name("jeremysmith_test_session");
session_start();

$_SESSION['start_time'] = time();

if($_SESSION['start_time'] < $_SESSION['start_time'] + 500) {
  printf("Time out be out dated!");
}

 

Just does not seem to want to work, is there any reason for this, that you could think of?

 

I appreciate any replies,

Jeremy.

Link to comment
https://forums.phpfreaks.com/topic/236832-correct-way-of-doing-a-php-timeout/
Share on other sites

Oh ok then that is fine.

 

Will work this one out and try it out maybe on a subsequent page, just to make it feel like a real system so to speak.

 

I mean for a user defined time out, it is in seconds is not it? I mean if a user was to say not use a no time out, in a checkbox element, they could say want their login valid for 60minutes, but in the way their inputting it, would be multiplied by 60?

 

Am I thinking about this correctly?

 

Plus if I wanted to do purely MySQL authentication time outs, then I would set when the users session would become invalid right? Saying something like:

 

<?php
['sessiontime'] <= time();
?>

 

Am I thinking alright about this?

 

Thank you for your reply and I look forward to your next response,

Jeremy.

Sorry it does not matter got it working now:

 

if(time() >= $_SESSION['timeout'] )

 

Obviously me just waffling, but got it working, using say time() + 60 * 60 (so I can theoretically set a text box, that a user can enter to say how long they want their session (if I allow this), for them to stay logged in or a checkbox to allow them to stay permenantly logged in.

 

Thank you for all your help, just needed to go over some logic.

 

Jeremy.

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.