Blog Details

Cookies


                                
                                    <h2>* PHP Cookies :-</h2>
<h2>What is a Cookie?</h2>
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
<h2>How to Create a Cookie?</h2>
The setcookie() function is used to set a cookie.
<h2>Syntax :-</h2>
setcookie(name, value, expire, path, domain);
<h2>Example 1 :-</h2>
&lt;?php
setcookie("user", "Alex Porter", time()+3600);
?&gt;

&lt;html&gt;
.....
<h2>Example 2 :-</h2>
&lt;?php
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);
?&gt;

&lt;html&gt;
.....
<h2>How to Retrieve a Cookie Value?</h2>
&lt;?php
// Print a cookie
echo $_COOKIE["user"];

// A way to view all cookies
print_r($_COOKIE);
?&gt;
<h2>How to Delete a Cookie?</h2>
&lt;?php
// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?&gt;
                                    


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote