how do i go about this ?

This is a discussion on "how do i go about this ?" within the PHP Forum section. This forum, and the thread "how do i go about this ? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 17th, 2007, 10:10
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
how do i go about this ?

I have a function that allows my users to search my database, and i want to limit the mumber of queries a user can do in a given 24 hour period.

I can write a script that increments a field in my database everytime a user conducts a search, and i can stop them searching if this value is at a given limit.

But how do i go about resetting this field to zero every 24 hours?
Reply With Quote

  #2 (permalink)  
Old Mar 17th, 2007, 10:55
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

I don't think this would be hard for a clever lad, you're just looking at the wrong end of the code. Mysql has both "if" and "time" functions. Have PHP send the query and do the coding on the mysql end. You might even think about having the "sorry, try again tomorrow" code in the database!

Otherwise, you're looking at multiple queries and a convoluted mess of php. I think doing the "if" code in mysql is going to be a lot cleaner, after all is said and done. Once you get the complex query working, you'll have one (longish) line of code that will do the whole thing.

Another thought is that you might do an initial query to check the time-counter, and just lock the person's access.

I'd almost do this for you just for fun/learning -- my mysql could really use some study time -- except I suspect you'll enjoy doing it yourself.

As a personal preference, I would not use any global variables except $_POST for this (or any page where user input can result in a change to the db).
Reply With Quote
  #3 (permalink)  
Old Mar 17th, 2007, 11:13
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

Hmm, answered every question except the one you asked.

The first theoretical approach that comes to my (alleged) mind is:
Code: Select all
access 'counter number' and 'timestamp a' [timestamp of first query in period]
if ('time' - 'timestamp a') > 86400 [note, should work if timestamp a is 0]
...perform search;
...reset timestamp a;
...set 'counter' to 1;
else
...if 'counter' < [maximum search number]
......perform query;
......counter +1;
...else 
......error message;
......exit and/or clear;

Last edited by masonbarge; Mar 17th, 2007 at 11:17. Reason: spacing didn't show
Reply With Quote
  #4 (permalink)  
Old Mar 18th, 2007, 01:26
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

sorry if im missing something here... (st patricks and all hic)

But wouldnt i still need to find a way to automatically reset the counter when the clock ticks over to midnight?
Reply With Quote
  #5 (permalink)  
Old Mar 18th, 2007, 23:56
Junior Member
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

If you want something simple and quick you could always set up a simple Cron job to reset the counter to 0 across the db table and set it to run at midnight daily...
Reply With Quote
  #6 (permalink)  
Old Mar 21st, 2007, 09:37
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

This wasnt anywhere near as hard as i thought it was going to be.

I just used a unix timestamp to calculate if their last search was 12 hours or more ago... if it was i delete all entries in the data base and start incrementing the counter again.
Reply With Quote
  #7 (permalink)  
Old Mar 22nd, 2007, 15:16
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

Yar, that's what I was thinking. Set counter to "1" every 24 hours.
Reply With Quote
  #8 (permalink)  
Old Mar 23rd, 2007, 07:52
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how do i go about this ?

I was thinking a cron job, but that works too Cron jobs are soooooo wonderful.
Reply With Quote
Reply

Tags
php

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:44.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43