Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Sessions, Cookies, Get and
Jaseena A P
Muhammed A P
What is a cookie?
Cookies are a mechanism for storing data in the
remote browser and thus tracking or identifying
A cookie is a small file that the server embeds on the
user's computer. Each time the same computer
requests for a page with a browser, it will send the
cookie too. With PHP, you can both create and
retrieve cookie values.
HOW to create a cookie?
The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE
the <html> tag.
setcookie(name, [value], [expire], [path], [domain],[se
This sets a cookie named "uname" - that expires after
<?php setcookie("uname", $name, time()+36000); ?>
<html> <body> …
How to retrieve a cookie value?
To access a cookie you just refer to the cookie name as a
variable or use $_COOKIE array
Tip: Use the isset() function to find out if a cookie has been
echo "Welcome " . $uname . "!<br />";
echo "You are not logged in!<br />"; ?>
How to delete a cookie?
It will expire
Cookies must be deleted with the same parameters as
they were set with. If the value argument is an empty
string (""), and all other arguments match a previous call
to setcookie, then the cookie with the specified name will
be deleted from the remote client.
Cookies are small pieces of data that a server sends
to a browser for storage. When a browser contacts a
server, it sends along any cookies for that server
under the variable $_COOKIES. Similarly, a server can
set one or more cookies on the browser for retrieval
at a later time.
Cookies are sent with Web page headers, so any setting
of cookies must take place BEFORE the DOCTYPE line in
an HTML/PHP script.
PHP function setcookie specifies a cookie ID, a value,
and a length of time for which the cookie will be kept by
PHP variable $_COOKIE is an associative array that
maintains the list of cookies set previously.
Session support in PHP consists of a way to preserve
certain data across subsequent accesses. This enables us
to build more customized applications.
The session support allows us to register arbitrary
numbers of variables to be preserved across requests.
A visitor accessing our web site is assigned a unique
id, the so-called session id. This is either stored in a
cookie on the user side or is propagated in the URL.
How to create a session
The session_start() function is used to create
How to Retrieve a Session Value
Register Session variable
session_register('var1','var2',...); // will also create a session
PS:Session variable will be created on using even if you will
not register it!
$_SESSION['count'] = 0;
How to Delete a Session Value
How to destroy a session:
Effectively, session variables are cookies that remain active
only while the browser is actively interacting with the
server. When time elapses, or when we close our browser,
the session variables disappear.
some notes regarding session variables
A script uses session_start() to initialize and register any
Session variables are sent with Web page headers, so any
setting of session information must take place before
the DOCTYPE tag.
PHP variable $_SESSION is an associative array that
maintains the list of session variables set previously.
PHP function isset determines whether a
specific $_SESSION field has a designated value.
PHP function unset removes a session value that was sent
previously, and session_unset() removes all session values.
Using the GET and POST methods , the browser
client can send data to the web server.
PHP the GET and POST methods are used to retrieve
information from forms , such as user input.
These methods are used data handling forms.
GET Method is less secure because information sent
from a form with the GET method is visible to every
The GET Method has limits on the amount of
information to send because URL lengths are limited.
The browser appends the data to the URL.
The GET method can’t be used to send binary
data,like images or Word documents,to the server
In the GET method page and encoded information are
separated by the question mark (?) sign.
POST Method is Secure because information sent from
a form with the POST method is invisible to every one.
The POST Method has no limits on the amount of
information to send because URL lengths are
The browser doesn’t append the data to the URL.
The POST method can be used to send binary data,like
images or Word documents,to the server
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Ph: + 91 – 495 40 25 550
Start up Village