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

tracking web visitors
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

4/17/13 1

Computer Science

CS108: Lecture 26 Tracking Web Visitors

Aaron Stevens

Computer Science

What You’ll Learn Today

  • How do you know who’s using your Application?
  • Using hidden fields to keep session state
  • HTTP Environment Variables
  • Cookie Cookie Cookie!
slide-2
SLIDE 2

4/17/13 2

Computer Science

Session State

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

Computer Science

Hidden HTML Form Fields

Consider this web application: HTML code which creates the buttons:

slide-3
SLIDE 3

4/17/13 3

Computer Science

Hidden HTML Form Fields

Here’s the Python code to generate the HTML Form:

Computer Science

HTTP Environment Variables

Show: snoop.py Discuss environment variables

slide-4
SLIDE 4

4/17/13 4

Computer Science

Cookie Cookie Cookie!

Computer Science

Session State: Cookies

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

slide-5
SLIDE 5

4/17/13 5

Computer Science

Session State: Cookies

Computer Science

How Cookies Work

Web Browser (client) Web App (server) GET / GET + Cookie RESP: login form RESP: cookie + data No Cookie? Send login form Yes Cookie? Send cookie + regular response GET + login form RESP: cookie + welcome Got login form? Send cookie + welcome message

slide-6
SLIDE 6

4/17/13 6

Computer Science

Setting a Cookie

Upon authentication, the server-side app can set a cookie to the client’s browser:

Computer Science

Retrieving a Cookie

Browser sends the cookies to the server in the HTTP request. Web app reads from

  • s.environ:
slide-7
SLIDE 7

4/17/13 7

Computer Science

Cookies get saved in the browser

Computer Science

First Things First: Look for Cookies

Cookies are sent by browser to server, received with HTTP request, stored in environment variables.

slide-8
SLIDE 8

4/17/13 8

Computer Science

No Cookie? Ask User to Ident

Computer Science

Setting the Cookie

slide-9
SLIDE 9

4/17/13 9

Computer Science Computer Science

What You Learned Today

  • Using hidden fields to keep session state
  • HTTP Environment Variables
  • Cookie Cookie Cookie!
slide-10
SLIDE 10

4/17/13 10

Computer Science

Announcements and To Do

  • 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.