Hi, I have been coding for about a week now.. I recently created some code that simply monitors how many times a form has been submitted. If it exceeds the set amount, the form disappears and message is displayed stating wait 5 mins before trying again. I thought session_set_cookie_params(60 * 30); would handle expiration?
Tried alternatively, adding condition to unset session when time has expired but I must be missing something. Looked into many topics but could not find the answer...
Please help me fix problem and understand what's going on here.
It works perfect in every way for me, except my session is not expiring?
One bad thing I have just come across is my $timestamp is incrementing when it should be only a timestamp?
Thanks in advance for your valued time~
// set the PHP session id (PHPSESSID) cookie to a custom value
// so you would need to call it before session_start().
$timeoutseconds = 300;
session_set_cookie_params($timeoutseconds);
// you have to open the session first
// This call either creates a new session or finds an existing one.
session_start();
// Check if the value for "count" exists in the session store
// If not, set a value for "count" and "start"
if (!isset($_SESSION["count"]))
{
$_SESSION["count"] = 0;
$_SESSION["start"] = time();
}
else {
// Increment the count
$_SESSION["count"]++;
}
$sessionId = session_id();
$timesClicked = $_SESSION["count"];
$timestamp = $_SESSION["start"]= time();
$timeNow = time();
$timeout = $timestamp-$timeoutseconds;
if (isset($_SESSION["count"])) {
echo "<center><br>Session name - ".$sessionId;
echo "<center>Times clicked = ".$timesClicked;
echo "<br><br>Start time - ".$timestamp;
echo "<br>End time - $timeout</center>";
echo "<br><br>Time now - $timeNow";
echo "<br>Set expire time - ".$timeoutseconds." in seconds</center>";
if ($timeNow - $timeout) {
//unset($_SESSION['count']);
}
}