COOKIES AND SESSIONS.

Slides:



Advertisements
Similar presentations
CookiesPHPMay-2007 : [‹#›] Maintaining State in PHP Part I - Cookies.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
V 1.0 OE NIK 2013 PHP+SQL 5. Password management (password hashing) Stateless HTTP, storage methods Login form 1.
Session Management A290/A590, Fall /25/2014.
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
Chapter 10 Maintaining State Information Using Cookies.
Lecture 16 Page 1 CS 236 Online Cross-Site Scripting XSS Many sites allow users to upload information –Blogs, photo sharing, Facebook, etc. –Which gets.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Cookies, Sessions, and Authentication Dr. Charles Severance
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
CS453: State in Web Applications (Part 1) State in General Sessions (esp. in PHP) Prof. Tom Horton.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Session tracking There are a number of problems that arise from the fact that HTTP is a "stateless" protocol. In particular, when you are doing on- line.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Nic Shulver, Introduction to Sessions in PHP Sessions What is a session? Example Software Software Organisation The login HTML.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Cookies & Session Web Technology
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each.
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Sessions, Cookies, &.htaccess IT 210. Procedural Issues  Quiz #3 Today!  Homework #3 Due Friday at midnight UML for Lab 4  Withdraw Deadline is Wed,
MEMBERSHIP AND IDENTITY Active server pages (ASP.NET) 1 Chapter-4.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
CP476 Internet Computing CGI1 Cookie –Cookie is a mechanism for a web server recall info of accessing of a client browser –A cookie is an object sent by.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Google App Engine Sessions and Cookies ae-09-session
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
How to maintain state in a stateless web Shirley Cohen
Cloud Computing Computer Science Innovations, LLC.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Internet Flow By: Terry Hernandez. Getting from the customers computer onto the internet Internet Browser
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting.
LOGIN FORMS.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
GENERAL SECURITY CONSIDERATIONS.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
CACHING TO IMPROVE PERFORMANCE
PHP – Hypertext Preprocessor.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● / www,histpk.org Hidaya Institute of Science & Technology
Cookies Tutorial Cavisson Systems Inc..
ITM 352 Cookies.
Cookies and Sessions Charles Severance
Cross-Site Forgery
Web Programming Language
Cookies and Sessions in PHP
Uses Of Encryption Algorithms
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
CSE 154 Lecture 21: Sessions.
Web Programming Language
Cookies and sessions Saturday, February 23, 2019Saturday, February 23,
Cookies and Sessions.
Web Programming Language
Presentation transcript:

COOKIES AND SESSIONS

HTTP is “stateless” By default, web servers are “forgetful” As far as they can tell, every request comes from a totally new and different browser – (Not exactly true. We'll discuss persistent connections in the context of performance.)

Pros of stateless servers Chief benefit: Potential for replication – Improved performance: A sysadmin can fire up N copies of a website (on N machines) and any machine can serve each request. – Improved reliability: If a machine crashes, then another can be started up in its place, and no data gets lost in the process.

Cons of stateless servers Chief problem: Keeping track of which requests "go together" – Security challenge: If a user submits username & password in http request X, then tries to access resources in http request Y, how does the server know that request Y is from somebody who already logged in? By the time that request Y comes in, the server will already have forgotten that request X ever occurred. And on a replicated system, request Y might be served by a different machine than request X.

Cookies to the rescue! Reminder: – Cookie = a piece of data that is automatically copied between the client and server Cookies can be set by the client (as in the last unit) or by the server.

A simple way to use cookies for login… When user sends a valid username & password in request X, the server replies with a cookie containing the username & password When user subsequently makes request Y, the browser sends along the cookie. – Sounds appealing: user only needs to log in once – Serious security hole: anybody who gets his hands on the user's computer can see cookies

Using just cookies for login Browser Server Type username & password Send username & password Cookie = usernm&pwd Authenticate Click a link or whatever Request page (send cookie) Send back page Warning This design contains a serious security hole.

A more secure way of cookies+login When user sends a valid username & password in request X, the server replies with a cookie containing a secret that the client couldn't possibly have guessed. When user subsequently makes request Y, the browser sends along the cookie. – Since the client couldn't have guessed this value without logging in, the server knows that the user did in fact previously log in.

Using cookies for login Browser Server Filesystem or Database Type username & password Send username & password Store a random number valid only for next 10 minutes Cookie = the random # Authenticate Click a link or whatever Request page (send cookie) Check if the number is right; if so, give another 10 minutes Send back page

Session = state stored across requests This is what we call a "session" Session is basically an add-on to the basic http functionality of a website – So that the website can remember information across requests. You can store lots of stuff in session – Numbers, strings, stringified objects, …

Pros of sessions Stores information between requests Much more secure than the simple cookie- based approach I showed you – A bad person would need to steal the random number (cookie) within 10 minutes of its creation

Cons of sessions Requires your web server to have write-access to some sort of storage medium – File system, database, …, if you want replication – Otherwise just use memory (lost on server crash) Requires user to access site every few minutes – Though you can configure longer or shorter times – This is a tradeoff between usability & security. – EECS servers currently are set to 24 minutes.

Simple example of using session <?php session_start(); // MUST BE the 1st line of your php if (isset($_SESSION['numhits'])) $_SESSION['numhits'] = $_SESSION['numhits']+ 1; else $_SESSION['numhits'] = 1; echo "You hit my server ".$_SESSION['numhits']." times."; ?>

Authentication (Using hardcoded username&pwd for now) <?php session_start(); /* login.php */ if (array_key_exists("username", $_REQUEST) && array_key_exists("password", $_REQUEST)) { /* here is where we would check the username and password */ $_SESSION['uid'] = 1; echo ' View Inventory '; } else { ?> Username: Password: <?php } ?> <?php session_start(); /* inventory.php */ if (isset($_SESSION['uid'])) echo "This is where we would show inventory."; else echo "You need to Log in "; ?>

You can set cookies without session <?php $nhits = isset($_COOKIE['numhits']) ? $_COOKIE['numhits'] : 0; $nhits = $nhits + 1; setcookie('numhits', $nhits, time()+86400*365); /* expires in 365 days */ echo "You hit my server ".$nhits." times."; ?>

Summarizing cookies vs sessions Cookies – Little bits of data that are stored on client but also copied automatically to the server – Useful for storing little bits of data on the client, but they are visible to everybody So don't store sensitive data in cookies Sessions – Data is stored on the server (e.g., filesystem), keyed by a random number – The random number is sent as a cookie to the browser – And the random number expires after a little while

When to use cookies vs sessions Use cookies when – You need to save a small amount of data between requests, and it doesn't need to be kept secret Use sessions when – You need to save a larger amount of data between requests, or when the data needs to be secret

Examples of information not to store in unencrypted cookies Passwords Credit card numbers Social security numbers Student ID numbers Birthdates List of diseases the user has contracted Anything that must be kept secret

Yet another caveat After all of those warnings, you still can save secret data in cookies, IF IT IS ENCRYPTED But we don't really use encrypted cookies much because it can cause usability problems.