note 55756 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 15 Jul 2007 12:46:47 +0000 |
| Subject: | note 55756 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128575@lists.php.net to get a copy of this message | ||
Note Submitter: baced2001 at freenet dot de
----
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
}
?>