2. Definition
:
Time span during which a browser interacts with
particular server.
Begins:
When a browser becomes connected to a particular
server.
Ends:
When browser ceases to be connected to that server coz:
1)Becomes connected to different server
2)Or it is Terminated
3. HTTP – STATELESS PROTOCOL
STATELESS- No means to store information about
a session
USES:
1) Many web sites creates profiles of clients by
remembering which parts of the site was
pursued–
ADVERTISEMENTS.
2) Server recognizes request from a client(who has
made earlier requests) from same site–
CUSTOMIZED INTERFACE.
4. -
Provides General Approach To Store information
about SESSIONS on Browser Itself.
-
Created by some software system on server such
as CGI program.
(CGI- Protocol used between browser and software
on server)
-
.
5.
A text file which a website can store on its visitors‟
hard drives
Made up of numbers and letters
Generally, cookies are a simple ID file
Sometimes they can store more complicated
information
Also called “name-value pairs”
6.
Most Cookies store just 1 data value
A Cookie may not exceed 4 Kb in size
Browsers are preprogrammed to allow a total of 300
Cookies, after which automatic deletion based on
expiry date and usage
Cookies have 3 key attributes: name, value and expiry
date
7. Sites
use cookies to…
Track number of visitors
First timers vs. returning visitors
How often the user visits the site
Why?
Frequent Buyer example
$$$ from Advertisers
8. You
can find cookie files on your hard
drive, your “C” drive.
9. 1)Stores info about msg.
2)Can Include 1 or more cookies
HEADER
MESSAGE
Request
SERVER
BROWSER
Response
10. 1. User sends a request for page at www.example.com for
the first time.
page request
11. 2. Server sends back the page xhtml to the browser AND
stores some data in a cookie on the user‟s PC.
xhtml
cookie data
12. 3. At the next page request for domain www.example.com,
all cookie data associated with this domain is sent too.
page request
cookie data
13. ANATOMY OF A (SIMPLE) COOKIE
String of text with these attributes:
The domain and path for which the cookie is valid
The name of the cookie
The value of the cookie
The expiration date of the cookie
Whether a secure connection needed
to use the cookie
14.
Cookies allow servers to record browser activities,
Hence considered as a privacy concern.
Accordingly, browsers allow the client to change
the browser setting to refuse to accept cookies from
servers.
Drawback- clients that reject them render them
useless.
15. CGI.pm module includes support for cookies in
Perl through cookie function.
Serves two tasks:
1) To Create a cookie
2) To retrieve existing cookies from HTTP
header of a request.
16.
Form of call is:
cookie(-name => a_cookie_name,
-value => a_value,
-expires => a_time-value)
17. cookie name- string
value- scalar value, including references to arrays
and hashes
expires - specifies lifetime of a cookie,
can be expressed in many different units.
Example: +3d specifies 3 days
s - seconds
m - minutes
h - hours
M - months
y - years
now - right now
-ve value - kills cookie
18. Calling cookie function
1) Without parameters: Returns hash of all of the
cookies in the HTTP header of current request.
2) To retrieve the value of 1 cookie, the cookie
function is called with the name of the cookie.
For ex:
$age=cookie („age‟);
Gets the value of cookie named age.
19. Prog block To display all
cookies(with both name and values)
in a CGI prog use:
print “Cookie Name t Cookie value <br/>”;
foreach $name(keys cookie())
{
print “$name t cookie($name) <br/>”;
}
20. In CGI.pm,
A cookie is placed in the HTTP header when
header function is called with cookie as a
parameter passed to it as follows:
header(-cookie => $my_cookie)
21.
Calls time function – time returns current time in
seconds since January 1,1970.
Converts the number of seconds into nine values:
1)$sec - seconds
2)$min - minutes
3)$hour - hour
4)$mday - day of the month
5)$mon - month (coded as 0 to 11)
6)$year - number of years since 1900
7)$wday - day of week (coded as 0 to 6; 0-sunday)
8)$yday - day_of the year
9)$isdst - Boolean; specifies whether the given time
is in daylight savings time
22. PROG TO DISPLAY ALL NINE VALUES
RETURNED BY
localtime:
#time_date.pl
#Input: None
#Output: The nine values returned by localtime
($sec, $min, $hour, $mday, $mon, $year, $wday,
$yday, $isdst) = localtime;
25.
For days of the week, we often prefer to get the
names rather than numbers…
this can be done in Perl as:
$day_of_week=(qw(Sunday Monday Tuesday
Wednesday Friday
Saturday))[(localtime)[6]];
where subscript 6 is for $wday
26. CGI PROG FOR CREATING GREETING
FOR VISITORS:
#!/usr/bin/perl
# day_cookie.pl
# A CGI program to use a cookie to remember the
day of the last login from a user and display it when
run
Use CGI “:standard”;
27. #>>> Get the existing day cookie, if there was one
@last_day = cookie(„last_time‟);
#>>> Get the current date and make the new
#>>> cookie
$day_of_week = (qw(Sunday Monday Tuesday
Wednesday Friday
Saturday))[(localtime)[6]];
$month=(qw(January February March April May
June July August September October
November December))[(localtime)[4]];
$day_of_month = (localtime)[3];
28. @day_stuff = ($day_of_week, $day_of_month,
$month);
$day_cookie = cookie(-name => „last_time‟,
-value => @day_stuff,
-expires => „+5d‟);
#>>> Produce the return document
#>>> First, put the cookie in the new header
print header(-cookie => $day_cookie);
print start_html(„This is day_cookie.pl‟);
29. #>>> If there was no day cookie, this is the first
#>>> visit
if(scalar(@last_day) == 0)
{
print “Welcome to you on your first visit to
our site<br/>”;
}
30. #>>> Otherwise, Welcome the user back and give
#>>> the date of the last visit
else
{
($day_of_week, $day_of_month, $month) =
@last_day;
print “Welcome back! <br/>”,
“Your last visit was on “,
“$day_of_week, $month $day_of_month
<br/>”;
}
print end_html;
32. MMMM! COOKIES…
They remember usernames for various sites that
require log-in
Also have the option to remember your
passwords for you!
They allow you to shop as you browse via online
shopping carts!
Cookies provide user customization of sites, like
weather.com & msn.com
33. COOKIE SCOPE: CAN DO
Store and manipulate any information you explicitly
provide to a site
Track your interaction with parent site such as pages
visited, time of visits, number of visits
Use any information available to web server including:
IP address, Operating System, Browser Type
34. LIFE WITHOUT COOKIES…
Many sites are heavily dependent on
cookies and may not function well
without them
Some may not function at all
Erasing cookies prevents visitors from
making use of certain amenities sites
offer
35. CONCLUSION
Cookies
were originally created as harmless
pieces of text for user convenience
Along
the way, some evil geniuses found a
way to exploit them for business
The
paranoia arises from the invisible nature
of cookie transactions and inadequate
information about their ability.