Jump to content

Session length?


Crew-Portal

Recommended Posts

How in the world do I do something like...

A user visits a page, after they finish with that page (By leavin to another location) It starts a timer that wont allow them to reaccess the page for 10 whole long boring minutes. It has to be with sessions but it cant conflict with any of the previous sessions set! Can anyone help?!?! And dont send me to php.net please, because I have read the stuff thier and I dont understand how it works!

Link to comment
Share on other sites

The only real way of doing this is to set a timestamp (last_active) within a cookie and check against this. However, the cookie can only be set when the user requests a page. trying to set a cookie when a user leaves will be alot more difficult.

 

You may be able to do something using Ajax, but really, and method you find will be pretty unreliable.

Link to comment
Share on other sites

You can't really keep someone off like that. Sessions cookies can be easily deleted.

Maybe a temporary ip ban. But that can be unreliable. 

You can try sessions but it won't be a sure fire way to keep anyone away.

<?php
session_start();
$tstamp = time();
$expires = $tstamp + 600;//time stamp + 600 seconds (10 mins)

if(!isset($_SESSION['expiry']) ) {
    $_SESSION['expiry'] = $expires;
}
else {
    $timeleft = $_SESSION['expiry'] - $tstamp;
    if($timeleft > 0) {
        exit('You can not access this site for another '.$timeleft.' seconds');
    }
    else {
        $_SESSION['expiry'] = $expires;
    }
}
?>

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.