note 55756 added to function.strtotime

From: Date: Fri, 12 Aug 2005 11:55:44 +0000
Subject: note 55756 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-93491@lists.php.net to get a copy of this message
if you'd like to create an ip- or cookie-based counter, you've to check the time passed since his last visit. the first way is to save the current date&time and add the timeout while checking: <?php function isTimedOut($tsLast, $intTimeoutSecs) { $tsTimeout = strtotime("+ " . $intTimeoutSecs . " seconds", $tsLast); return ($tsTimeout < mktime()); } function TimestampToDBDate($ts) { return date("Y-m-d H:i:s", $ts); } // $last_visit <-- DB-Entry if (isTimedOut($lastvisit, 60*60*24)) { // count !!! $last_visit = TimestampToDBDate(mktime()); // $last_visit --> DB-Entry } ?> and the second way is to add the timeout while saving the current time&date: <?php function CreateTimeoutTimestamp($intTimeoutSecs) { return strtotime("+ " . $intTimeoutSecs . " seconds", mktime()); } function TimestampToDBDate($ts) { return date("Y-m-d H:i:s", $ts); } // $next_count_date <-- DB-Entry if (mktime() > $next_count_date) { // count !!! $next_count_date = TimestampToDBDate(CreateTimeoutTimestamp(60*60*24)); // $next_count_date --> DB-Entry } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55756 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55756&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55756&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55756&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55756&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55756&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55756&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55756&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93491) next »