Storing Multiple Values in One Cookie using PHP

<?php $info = array("xyz", "yellow", 22); setcookie("usr", serialize($info)); ?> <html><head><title>Multiple Cookie Values</title></head> <h2>$_COOKIE[]</h2> <b> <?php if(! empty($_COOKIE[’usr’])){ $cookie_data= $_COOKIE[’usr’]; $cookie_data=stripslashes($cookie_data); $cookie_data=unserialize("$cookie_data"); echo "What’s in the cookie array< br />"; print_r($_COOKIE); echo "<pre>Unserialized data< br />"; print_r( $cookie_data); } ?> </b> </font> </body>
Continue reading…

Enjoyed this post? Share it!

 
 

Understanding persistent cookies

A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use […]
Continue reading…

Enjoyed this post? Share it!

 
 

Cookies in PHP : Part 3 – Retrieving a cookie

The $_COOKIE associative array is used to retrieve the value of a cookie from user’s computer. This is a ‘superglobal’, or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods. Example code: 1 […]
Continue reading…

Enjoyed this post? Share it!

 
 

Cookies in PHP : Part 2 – Creating a cookie

The setcookie() function is used to create a cookie. The seetcookie() function should be called before the tag in the page. Syntax: setcookie(name, value, expire); name specifies the name of the cookie. This name is later used to retrieve the cookie. The argument value specifies the value that needs to be stored on the user’s […]
Continue reading…

Enjoyed this post? Share it!