Cookies

441 views
321 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
441
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cookies

  1. 1.  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
  2. 2.  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.
  3. 3. - 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) - .
  4. 4.  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”
  5. 5.  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
  6. 6.  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
  7. 7.  You can find cookie files on your hard drive, your “C” drive.
  8. 8. 1)Stores info about msg. 2)Can Include 1 or more cookies HEADER MESSAGE Request SERVER BROWSER Response
  9. 9. 1. User sends a request for page at www.example.com for the first time. page request
  10. 10. 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
  11. 11. 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
  12. 12. 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
  13. 13.  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.
  14. 14.  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.
  15. 15.  Form of call is: cookie(-name => a_cookie_name, -value => a_value, -expires => a_time-value)
  16. 16. 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
  17. 17. 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.
  18. 18. 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/>”; }
  19. 19. 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)
  20. 20.  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 
  21. 21. 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;
  22. 22. print “$sec= $sec n”; print “$min= $minn”; print “$hour= $hour n”; print “$mday= $mday n”; print “$mon= $mon n”; print “$year= $year n”; print “$wday= $wdayn”; print “$yday= $yday n”; print “$isdst= $isdstn”;
  23. 23. $sec = 43 $min = 20 $hour = 10 $mday =19 $mon = 2 $year = 105 $wday = 6 $yday = 77 $isdat = 0
  24. 24.  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
  25. 25. 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”;
  26. 26. #>>> 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];
  27. 27. @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‟);
  28. 28. #>>> 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/>”; }
  29. 29. #>>> 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;
  30. 30. OUTPUT Welcome back! Your last visit was on Friday,March 22
  31. 31. 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
  32. 32. 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
  33. 33. 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
  34. 34. 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.

×