Only 1 request every 5 minute
6 posts
Page 1 of 1
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
I believe you can use cookies for that.
Take a look at this http://us3.php.net/setcookie
Take a look at this http://us3.php.net/setcookie
You can find me on Facebook or on Skype mihai_92b
XTechVB wrote:I believe you can use cookies for that.Thanks ill make a try
Take a look at this http://us3.php.net/setcookie
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
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
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
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
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.<?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'));
}
?>
You can find me on Facebook or on Skype mihai_92b
6 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023