You can delete the cookie by setting expiration date in the past
Example:
<?php
setcookie(“user”, “”, time()-3600);
?>
You can delete the cookie by setting expiration date in the past
Example:
<?php
setcookie(“user”, “”, time()-3600);
?>
// Display cookie value
<?php
echo $_COOKIE[“user_name”];
?>
You can view all cookies as follows
<?php
print_r($_COOKIE);
?>
Cookies can be created using the function ‘ setcookie(name,Value ,exp,path,domain)’ and its arguments are given below
Name :Name of the cookie that store the value and it is using to retrieve the stored data
Value : Its the value to be stored in the cookie ()generally we store login details like username , password)
exp : This is the the time that cookie lasts . if its not set ,the cookie will get destroyed when the browser closed .
path : This is path where the cookie to be stored
Domain: Domain where the cookie to be generated
Example
======
<?php
setcookie(“user_name”, “phpcodez”, time()+3600);
?>
Cookies can be used to store user information for future use . Cookies allow us to store data in users’ machine it self . Cookie is a small file that the server generate in user machine and using that file server can identify the user .When ever the browser send http request to the server , it send the cookies as well . Cookies can be created using PHP functions .
You can delete / Destroy session using the PHP function unset()
Example
<?php
session_start();
if(isset($_SESSION[‘phpcodez_views’]))
unset($_SESSION[‘phpcodez_views’]);
?>
Also its possible to completely delete the data using the function session_destroy ()
Example
<?php
session_destroy();
?>
Before using a session variable ,we must check if that variable exists in $_SESSION array and that can be done using the function .
Example
<?php
session_start();
if(isset($_SESSION[‘phpcodez_views’]))
$_SESSION[‘phpcodez_views’] = $_SESSION[‘phpcodez_views’]+ 1;
else
$_SESSION[‘phpcodez_views’] = 1;
?>
When you want to store information in a session use $_SESSION – this is where you store and retrive session data .
Example
<?php
session_start();
$_SESSION[‘phpcodez_views’] = 1; // store data
echo $_SESSION[‘phpcodez_views’]; //retrieve data
?>
Before you begin storing information in PHP session , you must start the session and it must be mentioned at the very beggining of your code .
<?php session_start(); // start PHP session! ?>
Session variables are used to store values that are required across multiple web pages .
A website can not remember anything about the users those who have already visited the site since the HTTP request does not have state . But at time , it is necessary to remember some details(eg should understand if a user is logged in or not ) . In such case we can use session that enable the website to store the information for later use .
Paste the following code into your .htaccess file
<ifModule mod_php4.c>
php_value zlib.output_compression 16386
</ifModule>