tracking web visitors
play

Tracking Web Visitors Aaron Stevens Computer Science What Youll - PDF document

4/17/13 CS108: Lecture 26 Tracking Web Visitors Aaron Stevens Computer Science What Youll Learn Today Computer Science How do you know whos using your Application? Using hidden fields to keep session state HTTP Environment


  1. 4/17/13 CS108: Lecture 26 Tracking Web Visitors Aaron Stevens Computer Science What You’ll Learn Today Computer Science  How do you know who’s using your Application?  Using hidden fields to keep session state  HTTP Environment Variables  Cookie Cookie Cookie! 1

  2. 4/17/13 Session State Computer Science HTTP is a stateless protocol.  Each request/response pair is a distinct conversation -- no “ memory ” How to keep track of a transaction which spans multiple pages?  confirm order and check out  e.g. shopping cart Some well-known ideas:  Use hidden form fields  HTTP provides out-of-band info about the environment  Cookies Hidden HTML Form Fields Computer Science Consider this web application: HTML code which creates the buttons: 2

  3. 4/17/13 Hidden HTML Form Fields Computer Science Here’s the Python code to generate the HTML Form: HTTP Environment Variables Computer Science Show: snoop.py Discuss environment variables 3

  4. 4/17/13 Cookie Cookie Cookie! Computer Science Session State: Cookies Computer Science A cookie is like a special bookmark shared between client and server in a “ session. ”  Server sets a cookie in HTTP response headers  Client will always include this cookie with requests  Cookie can be any key-value pairs as text.  Server typically uses the cookie to identify a client ’ s data in a database. http://tools.ietf.org/html/rfc2109.html 4

  5. 4/17/13 Session State: Cookies Computer Science How Cookies Work Computer Science Web Browser Web App (client) (server) GET / No Cookie? Send login form RESP: login form GET + login form Got login form? Send cookie + RESP: cookie + welcome welcome message GET + Cookie Yes Cookie? Send cookie + RESP: cookie + data regular response 5

  6. 4/17/13 Setting a Cookie Computer Science Upon authentication, the server-side app can set a cookie to the client ’ s browser: Retrieving a Cookie Computer Science Browser sends the cookies to the server in the HTTP request. Web app reads from os.environ : 6

  7. 4/17/13 Cookies get saved in the browser Computer Science First Things First: Look for Cookies Computer Science Cookies are sent by browser to server, received with HTTP request, stored in environment variables. 7

  8. 4/17/13 No Cookie? Ask User to Ident Computer Science Setting the Cookie Computer Science 8

  9. 4/17/13 Computer Science What You Learned Today Computer Science  Using hidden fields to keep session state  HTTP Environment Variables  Cookie Cookie Cookie! 9

  10. 4/17/13 Announcements and To Do Computer Science  Readings for this week:  HTML Tutorial: http://www.w3schools.com/HTML/  Cookies: http://webpython.codepoint.net/cgi_cookie  QUIZ 6 on FRI 4/19  Web applications, database integration  Session state, environment variables, and cookies  Lab Exam is THU 4/25  Covers material from Zelle book only (first half of semester)  Final project due THU 5/2 at 12pm.  5 points for early presentation on TUE 4/30 at 10am.  Use http://aaronstevens.youcanbook.me to make an appointment. 10

Recommend


More recommend