Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine time range between two consecutive queries

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
Hi there,
I made a script to login at which furthermore shows the selected data from the table using a query as a scrolling text, based on the Iframe and Javascript options (such as a short info-service). From the login scripts run Javascript that call other small PHP script that produces a query and then Javascript displays the resulting code in layer login skripte. All works beautifully if you use as a normal user, but I am afraid of the possibility that a some user holds down the whole time F5 to refresh page and so overloaded webserver and service crashes. Therefore I would like to know how to skip making a query if the previous query was less than 10 seconds, something like a flood prevention or prevention of multiple consecutive Search queries on some forums if the interval is less than a defined time. Thank you.

There is no good nor evil, just decisions and consequences.
 
use sessions.
in your query receiving script do this

Code:
session_start();
define("TIMEOUT', 60) ; //60 seconds
if (isset($_SESSION['lastQuery'])):
   if ($_SESSION['lastQuery'] + TIMEOUT >=  time()):
        $_SESSION['lastQuery'] = time();
        echo ''; //to avoid browser hangs
        session_write_close();
        exit;
   endif;
endif;
$_SESSION['lastQuery'] = time();
session_write_close();
//run query and output data
 
Thanks dude, I thought about that but wasn't sure is it good way. I thought also about cookies but this solution seems much easier for implementation. Thank you man.

There is no good nor evil, just decisions and consequences.
 
if someone keeps refreshing, direct them off to somewhere "inapropriate" !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top