Time limit between searches?
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #1
Time limit between searches?
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!
08-01-2012 03:43 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #2
RE: Time limit between searches?
Is not there a settings for this within MyBB? Pretty sure it does... try under server configurations or similar.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
08-01-2012 05:47 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #3
RE: Time limit between searches?
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:
1
2
3
4
5
6
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?

(This post was last modified: 08-02-2012 05:23 AM by mdb.)
08-02-2012 05:13 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Time limit between searches?
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

My Blog
08-02-2012 07:55 AM
Find all posts by this user Quote this message in a reply
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #5
RE: Time limit between searches?
Thanks Zinga,

I tried this:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	
$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?

(This post was last modified: 08-02-2012 04:42 PM by mdb.)
08-02-2012 04:38 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: Time limit between searches?
Both code paths will never be executed.
Perhaps check this condition

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


My Blog
08-02-2012 11:23 PM
Find all posts by this user Quote this message in a reply
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #7
RE: Time limit between searches?
(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
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Time limit between searches?
(08-03-2012 04:02 AM)mdb Wrote:  is greater than
And what's the greater than symbol again?

My Blog
08-03-2012 07:49 AM
Find all posts by this user Quote this message in a reply
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #9
RE: Time limit between searches?
(08-03-2012 07:49 AM)ZiNgA BuRgA Wrote:  And what's the greater than symbol again?

I hate me... haha

Thanks matie!
(This post was last modified: 08-03-2012 09:49 AM by mdb.)
08-03-2012 09:48 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: