note 65396 added to function.time

From: Date: Sun, 30 Apr 2006 00:06:38 +0000
Subject: note 65396 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-110144@lists.php.net to get a copy of this message
Generally we use this function to make some applications more secure. For instance, you are programming a poll for your website. Adding 1 to each selection in mysql database is the easiest way but there is a problem. Your visitors might be in a wicked situation and they might trick the system. In my opinion, this cause some mistakes. You can try this exercise: At first, create an additional table for your poll. It will include visitors IP and date of insertion. And of course, we use this command to save date in database. Now we'll decide to what the time is necessary for our project. If you know a little math, you can calculate that one day includes 86400 seconds. I think that its enough. After that, you must check datas from database, which is about the current visitors IP. We will use an IF function to learn visitors last usage of poll system. For example, this visitor had used this system. Get these datas from database and check what's the date? <? // You have to write there your database connection // I will use $row for mysql_fetch_array $ip=$REMOTE_ADDR; // VISITOR IP $date=$row['poll_date']; // DATE IN DATABASE $date2=time(); // NOW $sensitivity=86400; $date3=$date+$sensitivity; // WE WILL COMPARE DATES if($date3>=$date2) {echo "Thanks.";} // INSERT DATA TO DATABASE else {echo "You cant use poll system two times in a day"; // DONT INSERT DATA TO DATABASE ?> ---- Server IP: 139.179.10.17 Probable Submitter: 195.174.108.81 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/note/edit/65396 Del: integrated -- http://master.php.net/note/delete/65396/integrated Del: useless -- http://master.php.net/note/delete/65396/useless Del: bad code -- http://master.php.net/note/delete/65396/bad+code Del: spam -- http://master.php.net/note/delete/65396/spam Del: non-english -- http://master.php.net/note/delete/65396/non-english Del: in docs -- http://master.php.net/note/delete/65396/in+docs Del: other reasons-- http://master.php.net/note/delete/65396 Reject -- http://master.php.net/note/reject/65396 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110144) next »