Only 1 request every 5 minute

6 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Only 1 request every 5 minute
AnoPem
Hello people, can anyone help me, i need to make some sort of script for my page that only allows people to open the webpage 1 time every 5 minutes to avoid spam? can anyone point me out where i can read about it or help me with it ? and this should only count for 1 .php file
https://t.me/pump_upp
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: Only 1 request every 5 minute
XTechVB
I believe you can use cookies for that.
Take a look at this http://us3.php.net/setcookie
You can find me on Facebook or on Skype mihai_92b
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Only 1 request every 5 minute
AnoPem
XTechVB wrote:
I believe you can use cookies for that.
Take a look at this http://us3.php.net/setcookie
Thanks ill make a try
https://t.me/pump_upp
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Only 1 request every 5 minute
Filip
Hello,

Do you mean that site can be opened only once in 5 minutes (So 1 visit locks the site for 5 minutes) or site is user locked for 5 minutes?

-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Only 1 request every 5 minute
AnoPem
Filip wrote:
Hello,

Do you mean that site can be opened only once in 5 minutes (So 1 visit locks the site for 5 minutes) or site is user locked for 5 minutes?

-Filip

Yes excatly, but only for the person who opens it
https://t.me/pump_upp
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: Only 1 request every 5 minute
XTechVB
When i visited this page today i saw that you haven't found a solution yet, so i thought i'll give it a try (i hope i'm not too late) so here you go
Code: Select all
<?php
// Start the session engine. This is very important, without it nothing will work.
session_start();
// Set a page name.
$pageName = 'my-page'; // Here you can set your page name or some other identifier you want.
// Set a wait time.
$waitTime = 5; // Change this to how many minutes you want the user to wait
// If the session already exists then the user has been here before so get the visitTime from it (the minute when the user visited).
if(isset($_SESSION[$pageName])) {
	// If the difference between the current minute and the session minute is less then 5 minutes ($waitTime), then the user must wait to access the page again.
	if(date('i') - $_SESSION[$pageName]['visitTime'] < $waitTime) {
		echo 'You must wait ' . ($waitTime - (date('i') - $_SESSION[$pageName]['visitTime'])) . ' minutes before you can access this page again!';
	}
	else {
		// The user waited the set time, now show him the the content.
		echo "Page Content";
		// Update the session with the current minute so we can start the count again.
		$_SESSION[$pageName]['visitTime'] = date('i');
	}
}
else {
	// The user is visiting this page for the first time so show him the content.
	echo "Page Content";
	// Now set the session with the current minute.
	$_SESSION[$pageName] = $timeLmt = array('visitTime' => date('i'));
}
?>
This code will prevent anyone from accessing a page more then 1 time every 5 minutes. I hope this helps. :) :) Ooh and i haven't tested this for long periods of time so if you encounter any problems contact me.
You can find me on Facebook or on Skype mihai_92b
6 posts Page 1 of 1
Return to “Help & Support”