MyBB Hacks

Full Version: Time limit between searches?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys,
Is there a way to make a countdown so to speak to prevent a user from searching? Like for example 10 seconds between searches?

Cheers!
Is not there a settings for this within MyBB? Pretty sure it does... try under server configurations or similar.
Oh sorry I didn't mean for mybb's thread searches, but for a seperate query i'm adding.

I found this on the internet but am a little confused by it:

PHP Code:
session_start()
if(isset($_SESSION['ip']) && $_SESSION['last_search'] + 30 < time()) die('too early');

$_SESSION['last_search'] = time();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
// store the message


Could someone explain to me if that's the method I would use to store a persons last search time, and also how I could use that to add a check using that method for if a person made a search within the last 30 seconds, and if they did itll echo them some message, if not they can continue?

It's a function that you need to analyse and determine the solution for.
Ultimately you need some mechanism for:
  1. tracking people
  2. determining their last search time
  3. throwing an error if you find they've committed a search not long ago
Thanks Zinga,

I tried this:

PHP Code:
	
$limit = 10;
session_start();
if (isset($_SESSION['ip']) && $_SESSION['last_search'] + $limit < time()) {
	$nosearch = "Please wait {$limit} seconds between searches";
}
else {
	$_SESSION['last_search'] = time();
	$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
	while($banres = mysql_fetch_array( $data )) 
	{
		// fetching sql data
	}
}

However I can't figure out what is wrong with this code. It is basically ignoring my first if statement and always returning $nosearch as well going through my while loop, Can you spot what i'm doing wrong?

Both code paths will never be executed.
Perhaps check this condition

PHP Code:
$_SESSION['last_search'] + $limit < time()

(08-02-2012 11:23 PM)ZiNgA BuRgA Wrote: [ -> ]Both code paths will never be executed.
Perhaps check this condition

PHP Code:
$_SESSION['last_search'] + $limit < time()


Hmm, this really has me stumped.
As far as i'm aware the first time the user searches, the if statement should return false since $_SESSION['ip'] isn't set yet, so it should skip to the else statement and record the current time of the search. The 2nd time they try to search, the $_SESSION['ip'] var should be set, and then it should check if the recorded time of the first search + 10 seconds is greater than the current time. Obviously that can't be correct or it would work but... how is it wrong? Frown haha
(08-03-2012 04:02 AM)mdb Wrote: [ -> ]is greater than
And what's the greater than symbol again?
(08-03-2012 07:49 AM)ZiNgA BuRgA Wrote: [ -> ]And what's the greater than symbol again?

I hate me... haha

Thanks matie!
Reference URL's