Return to Snippet

Revision: 38426
at January 2, 2011 06:39 by claudiowebdesign


Initial Code
<?php
	function set_cronology($name,$value,$duration=7){
		$duration=time()+(3600*24*$duration);
		$max_stored_values=5;
		if(isset($_COOKIE[$name])){
			foreach($_COOKIE[$name] as $prop_crono=>$val_crono){
				if($val_crono==$value)
					return;
			}
			if($prop_crono<$max_stored_values)
				setcookie($name.'['.($prop_crono+1).']',$value,$duration);
			else{
				array_shift($_COOKIE[$name]);
				setcookie("$name[$max_stored_values]",$value,$duration);
			}
		}else
			setcookie($name.'[0]',$value,$duration);
		return;
	}
?>

Initial URL

                                

Initial Description
A little function used to set cookies as arrays of values instead of single combinations key->value. Note that it saves values as a stack.

Initial Title
Setting cookies like stack arrays

Initial Tags
php, array, function

Initial Language
PHP