how do i make timed events like once a user clicks somthing run the script in 20 minutes? or once they run a script they cant do it again for another 10 minutes or somthign?
PHP is certainly not the best language to achieve such effects, what you can only do is to use sleep function to stop execution of a script for a specified amount of time.
THis is easy. You can use PHP to simply log the IP address and timestamp of the user that clicked the action into a MySQL table. Then whenever someone clicks your action, check their IP against the table. If the timestamp < 20 minutes ago, just disable the action. Easy as pie.
Well, I guess it's easy if you've been coding for a few years You do a select against the time column in the table. For example, to make sure someone can't click the action again, you would run the MYSQL statement, "SELECT myIpAddress FROM myTable WHERE myIpAddress = '$userIpAddress' AND hour(myDate)> 17 and minute(myDate) > 52" This will make sure the time is greater than 17:52, or 5:52. You'll have to do the PHP statement which subtracts 20 minutes from the current time, but this SQL should help get you started.
Use cookies to store time. Every time user browses your web pages use time() function to check the current time and the one stored in the cookie. Code is going to be a bit complex though. More secure way is to store IP address and first visit time in mysql table and then continuously check the time in the database with that of the current time. This will waste time though and is a inefficient way if you get 1000's of visitors.
Here're the "complete" scripts. I haven't checked / run this script, sorry if there is an error. Create a table : named something, i use tbl_user_log for an example. Here are the columns : log_id => int primary key user_ip => varchar 64 not null last_action => big int 15 not null default 0 For example, there is a simple form. Every 20 mins, a user can submit the form and get "OK" message. If that user submits more than once every 20 mins, s/he will get "ERROR" message. We'll create 3 file : config.php => for configuration or such index.php => where the user views the form submit.php => here's the form target ---------- config.php <?php define('TIME_LIMIT', 60 * 20);// in seconds // put your connection code here mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('your_db') or die(mysql_error()); ?> PHP: ---------- index.php <html> ... <form action="submit.php"> <input type="submit" value="Let's go" /> </form> ... </html> PHP: ---------- submit.php <?php require('config.php'); // Delete expired record(s) $now = time(); // we'll delete record(s) with time less or equal to this value $limit = $now - TIME_LIMIT; $q = "DELETE FROM tbl_user_log WHERE last_action <= $limit"; mysql_query($q); // Get user's ip $user_ip = $_SERVER['REMOTE_ADDR']; // $user_ip .= $_SERVER['HTTP_X_FORWARDED_FOR']; // just to make all records have same length :) $user_ip = md5($user_ip); // Lets check in our database $q = "SELECT COUNT(*) FROM tbl_user_log WHERE user_ip = '$user_ip'"; $q = mysql_query($q); $r = mysql_fetch_array($q); // flag to define if the submission is OK $isOk = false; $isOk = ($r[0] < 1); if ($isOk) { // everything's OK // let's record it $q = "INSERT INTO tbl_user_log (user_ip, last_action) VALUES ('$user_ip', $now)"; mysql_query($q); // echo our message echo("OK"); } else { echo("Error, please wait."); } ?> PHP: