Wednesday, 10 July 2013

What is Cookies in php

Cookies


The state management object using to maintain the state of application Cookies stores the data in client memory location.
These data we can access from any web page within the application

Cookies stores the information in two location, Either Hard disk or Ram memory location of client system

Cookies are divided into Two types


1.In-memory cookies


If we create any cookie without explicit expiry tag comes under in memory cookies. In memory cookies stores the information
in clinet Ram memory location and destroys the data when user closed the browser


2.Persistence cookies


IF we create any cookies with explicit expiry tag
comes under persistence cookies . persistence cookies stores the data in Hard disk and delete the information when the lifetime
cookies complete

SET_cookies


By using this function we can create the cookies in php

$_COOKIES


By Using this global variable we can get the value of cookies.Cookies used in browser memory location that why we cannot access the cookies from one browse to another browser.


Example:
Page 1.php

<?php
set cookies('x',100);
echo "created cookies";
?>


page2.php

<?php
echo "value is ".$_COOKIE['x'];
?>


Steps to create persistence Cookies


1.Get the current date and time Information when user send the request to access the file where we created cookies.
2.Add lifetime to the current data and time to get expiry time.
3.Create cookies with that expiry tag.

Example:


<?php
set cookies('x',100);
Set cookies('y',1001,time()+1000);
echo $_COOKIES['x'];
echo $_COOKIES['y'];
?>


Persistence cookies will store in hard disk in a file of browser memory location
the name of that file is username@domain_name.

We can delete the cookies from client system by recreating the cookies with completed time.


Disadvantage of Cookies


1.Cookies stores the information in client system . that why client can delete the information or client can modify cookies data
2.cookies is storing limited amount of data
3.cookies can store only text data

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More