note 34814 added to function.md5
| From: | marc at NOSPAM dot giombetti dot com | Date: | Thu, 07 Aug 2003 14:18:09 +0000 |
| Subject: | note 34814 added to function.md5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53573@lists.php.net to get a copy of this message | ||
I use md5 to create a string that will be valid for X seconds!
One may use this function for cacheing reasons or even timeout functionality in a script.
/**
* valid_for_x_minutes() : Gernates an md5 hash that will be the same for $timeout minutes
* This function was intitialy used in combination with jpGraph to allow cacheing of multiple
* charts for a specified time.
*
* @param $timeout - Timeout in minutes
* @param $optional - An optional string to include to in the md5 string
* @return
*/
function valid_for_x_minutes($timeout,$optional){
if($timeout != "0"){
$hours = date("H");
$minutes = date("i");
$tmpval = ceil($minutes/$timeout)*$timeout;
if(!empty($optional)){
return md5("$tmpval$optional");
}else{
return md5("$tmpval");
}
}else{
return md5(time());
}
}
----
Manual Page -- http://www.php.net/manual/en/function.md5.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34814
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34814&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34814&report=yes