A cookie is create by using setcookie function Syntax setcookie name value expire path domain secure httponly Only the name parameter is required All other parameters are optional ID: 731197
Download Presentation The PPT/PDF document "Cookies Cookie :- A cookie is often use..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Cookies
Cookie
:- A cookie is often used to identify a user. 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.
A cookie is create by using
setcookie
()
function
Syntax
setcookie
(
name, value, expire, path, domain, secure,
httponly
);
Only the
name
parameter is required. All other parameters are optional.Slide2
Program to check whether a
Cookie exists or not
<?
php
$
cookie_name
= ‘bca-5-test-cookie’;
If (
isset
($_
COOKIE
[$
cookie_name
]));
{
echo ‘<b>’ . $
cookie_name
. ‘</b> is set’;
}
Else
{
echo ‘<b>’ . $
cookie_name
. ‘</b>
is not
set ‘;
}Slide3
Cookies
‘$_COOKIE’
is global
variable.
Global variables are in built variables that are used for specific purposes, and $_COOKIE is the global variable that allows us to use cookie data.
If we don’t use it, we cant access cookie data.
Isset
()
function is used to check whether cookie is set or not.Slide4
Program to set/create a cookie
<?
php
$
cookie_name
= ‘bca-5-test-cookie’;
$
cookie_value
= ‘ Testing browser cookie for BCA 5
th
Sem
’;
Setcookie
($
cookie_name
, $
cookie_value
);Slide5
Program to create
a
Cookie
with expiry time
<?
php
$
cookie_name
= ‘bca-5-test-cookie’;
$
cookie_value
= ‘ Testing browser cookie for BCA 5
th
Sem
’;
$
expiry_time
= time()+50;
Setcookie
($
cookie_name
, $
cookie_value
, $
expiry_time
);Slide6
How to view cookies in web browser ?
1.From
the Tools menu, select
Options.
2.If the menu bar is hidden press
alt
to make it visible.
3. At the top of the window that appears, click privacy.
4. To
manage cookie settings, from the drop-down menu under "History",
select
Use custom settings for history. Enable or disable the settings by
checking
or unchecking the boxes next to each setting
:
1. To allow sites to set cookies on your computer, select Accept cookies from sites. To specify which sites are always or never allowed to use cookies, click
Exceptions.
2. To accept third-party cookies, check Accept third-party cookies. In the "Keep until:" drop-down menu, select the time period you wish to keep cookies on your computer.
3. To specify how the browser should clear the private data it stores, check Clear history when Firefox closes. Click Settings.... Check the items to be cleared when you close
Firefox.
To
view or remove individual cookies, click remove individual cookies.
To remove all cookies, from the History menu, select clear your recent history. Click the arrow next to "Details" to expand the menu, check the items you want to clear, and then click Clear Now.
Slide7
Program to delete a cookie
You can delete a cookie by calling the same function
setcookie
() with the cookie name and any value (such as an empty string) and th
e time is need to be set in the past.
<?
php
Setcookie
(“username”, “ “, time()-3600);
?>