note 41591 deleted from function.setcookie by tomsommer

From: Date: Thu, 15 Apr 2004 21:57:04 +0000
Subject: note 41591 deleted from function.setcookie by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-68180@lists.php.net to get a copy of this message
Note Submitter: alberto_feldespato(at)lycos(dot)es ---- It's a function to make easy the expiration date of a cookie <? function easycookie($nombre, $contenido, $duracion){ /* $nombre is the name of the cookie $contenido is the cookie value $duracion must have the form: amount space measure unit the measure unit can be hour (h), day (d), month (m), year (y) or minute (min) Examples: easycookie("id", "eRh65GcdN7", "2 m") will expire after 2 months easycookie("lang", "es", "1 y") will expire after 1 year */ $a = explode(" ", $duracion); $unidad = $a[1]; $cantidad = $a[0]; switch ($unidad){ case "min": $duraciondefinitiva = time() + ($cantidad * 60); break; case "h": $duraciondefinitiva = time() + ($cantidad * 3600); break; case "d": $duraciondefinitiva = time() + ($cantidad * 86400); break; case "m": $duraciondefinitiva = time() + ($cantidad * 2678400); break; case "y": $duraciondefinitiva = time() + ($cantidad * 31536000); break; } setcookie($nombre, $contenido, $duraciondefinitiva); } ?>

« previous php.notes (#68180) next »