Reputation: 13
Hello i'm having trouble with making like a simple waiting time between 2 php requests like... i have this code (for example) :
readfile($link);
the visitor request this php code to download a file ... but within 10 seconds he requests another one ... i want to make a limit for the time like if he requested once he has to waiting from the first download to the allowance to the second request (download) 30 seconds ... any idea of how could this be done ? in php ... thank you in advance :)
edit : i tried with the help of the post below but did not work
if (!isset($_SESSION['last_download'])) $_SESSION['last_download'] = 0; {
if (time() - $_SESSION['last_download'] > 10){
$_SESSION['last_download'] = time();
echo $_SESSION['last_download'];
}else {echo"".time() - $_SESSION['last_download']."";}}
but its not saving the session ... any help ?
Upvotes: 0
Views: 5184
Reputation: 10371
but its not saving the session
Did you forget to include session_start()
?
Try
<?php
session_start();
if (isset($_SESSION['last_download']))
{
if (time() - $_SESSION['last_download'] > 10)
{
// allow download
$_SESSION['last_download'] = time();
echo $_SESSION['last_download'];
}
else
{
echo time() - $_SESSION['last_download'];
}
}
else
{
// session not set yet, set it now
$_SESSION['last_download'] = time();
}
?>
Upvotes: 2
Reputation: 50966
Just save last download time into a session
<?php
if (!isset($_SESSION['last_download'])) $_SESSION['last_download'] = 2; //time in past
if ($_SESSION['last_download'] && time() - $_SESSION['last_download'] > 10){
$_SESSION['last_download'] = time();
//allow download
}
Upvotes: 1