Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.

Slides:



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

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
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.
>> PHP: Access Control & Security. Authentication: Source Authentication Source Hard-coded File-Based The username and password is available inside the.
Page 1 PHP, HTML, STATE Achmad Arwan, S.Kom. Page 2 PHP ( PHP: Hypertext Preprocessor) A programming language devised by Rasmus Lerdorf in 1994 for building.
Chapter 10 Managing State Information Using Sessions.
Chapter 10 Managing State Information PHP Programming with MySQL.
Using Session Control in PHP tMyn1 Using Session Control in PHP HTTP is a stateless protocol, which means that the protocol has no built-in way of maintaining.
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.
Php cookies & sessions.
Chapter 10 Maintaining State Information Using Cookies.
Objectives Learn about state information
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
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.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Chapter 8 Cookies And Security JavaScript, Third Edition.
12/3/2012ISC329 Isabelle Bichindaritz1 PHP and MySQL Advanced Features.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
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
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
PHP Workshop ‹#› Maintaining State in PHP Part II - Sessions.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
SessionsPHPApril 2010 : [‹#›] Maintaining State in PHP Part II - Sessions.
PHP Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Advance web Programming Managing State Information (Cookies-Session) Date: 22 April 2014 Advance web Programming Managing State Information (Cookies-Session)
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.
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
PHP Cookies. Cookies are small files that are stored in the visitor's browser. Cookies can be used to identify return visitors, keep a user logged into.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
How to maintain state in a stateless web Shirley Cohen
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
 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 time the same computer requests.
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.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
HTTP Transactions 1. 2 Client-Server Model 3 HTTP HyperText Transport Protocol Native protocol for WWW Sits on top of internet’s TCP/IP protocol HTTP.
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.
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● / www,histpk.org Hidaya Institute of Science & Technology
Cookies Tutorial Cavisson Systems Inc..
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
ITM 352 Cookies.
Maintaining State in PHP Part II - Sessions
Web Programming Language
Cookies and Sessions in PHP
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.
<?php require("header.htm"); ?>
Cookies Cookie :- A cookie is often used to identify a user. A cookie is often used to identify a user. A cookie is a small file that the server embeds.
Maintaining State in PHP Part II - Sessions
Web Programming Language
Web Programming Language
Presentation transcript:

Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions

Open Source Server Side Scripting 2 ECA 236 HTTP  stateless  every single HTML page is separate from all others  no way to track individual users  no way to retain variables  one limited solution  append information to the end of a url  hidden form fields  a better solution  PHP cookies and sessions … href = “process_form.php?author=Mishka” …

Open Source Server Side Scripting 3 ECA 236 basic session functionality  track sessions using the superglobal $_SESSION  sessions driven by unique session ID  encrypted random number  stored on client side  stored as cookie or part of URL  allows tracking of session variables  stored on server  available to any page using session ID ca907cf7e881d1693b9d36518b4b3f3d

Open Source Server Side Scripting 4 ECA 236 cookies  what cookies are  text file  stored on visitor’s hard drive  contains textual information which can be retrieved and used in subsequent pages or visits  can be turned off by a user  what cookies are not  executable scripts  able to search a user’s hard drive for sensitive information

Open Source Server Side Scripting 5 ECA 236 cookies cont …  working with cookies  to test for their presence  view file structure of hard drive  open coolie in a text editor  change cookie settings in browser to prompt user before accepting any cookie  IE >Tools -> Internet Options >Security or Advance tab >choose to be prompted before accepting a cookie

Open Source Server Side Scripting 6 ECA 236 cookies cont …  cookies must be sent before any other data is sent from the server to the client  setcookie( ) function  one required parameter, the name of the cookie  five optional parameters  value  expire  path  domain  secure

Open Source Server Side Scripting 7 ECA 236 cookies cont …  syntax  this cookie is named myname, and contains the value Bob  do not use spaces, punctuation when naming a cookie  cookie name is case sensitive  this cookie is temporary, lasting only as long as the user’s browser remains open  cookies are limited to 4KB in size  browsers will accept no more than 20 cookies from any server setcookie( ‘name’, ‘value’, expire, ‘path’, ‘domain’, secure ); setcookie( ‘myname’, ‘Bob’ );

Open Source Server Side Scripting 8 ECA 236 cookies cont …  additional parameters  expiration date  sets length of time for cookie to exist  specified in seconds from Unix Epoch  if not set, cookie will persist until browser is closed  integer value, so it is not quoted  time( ) function returns seconds from Epoch setcookie( ‘name’, ‘value’, expire, ‘path’, ‘domain’, secure ); setcookie( ‘name’, ‘value’, time( ) );

Open Source Server Side Scripting 9 ECA 236 cookies cont …  additional parameters  path and domain  used to limit a cookie to a specific folder in a specific website  for example, to specify a cookie to be accessible only from a particular folder setcookie( ‘name’, ‘value’, expire, ‘path’, ‘domain’, secure ); setcookie( ‘name’, ‘value’, time( ) , ‘/my_folder/’ );

Open Source Server Side Scripting 10 ECA 236 cookies cont …  additional parameters  secure  integer value, so it is not quoted  if on, requires that a cookie be sent over a secure setting > 1 secure connection is required > 0 regular connection is sufficient  all parameters must be included  to skip one, use NULL or empty string setcookie( ‘name’, ‘value’, expire, ‘path’, ‘domain’, secure ); setcookie( ‘name’, ‘value’, time( ) , ‘ ‘, ‘ ‘, 1 );

Open Source Server Side Scripting 11 ECA 236 deleting cookies  a cookie will expire  when expiration date is reached  when browser is closed if not expiration date included  to delete cookies manually  send cookie of same name with no value  added precaution, set expiration to time in past setcookie( ‘name’ ); setcookie( ‘name’, ‘ ‘, time( ) – 300 );

Open Source Server Side Scripting 12 ECA 236 accessing cookie values  $_COOKIE  use appropriate cookie name as key  check for presence of cookie with isset( ) $x = $_COOKIE[ ‘cookie_name’ ]; if( !isset( $_COOKIE[ ‘username’ ] ) ) { header( “Location : // redirect to another page } else { // load this page }

Open Source Server Side Scripting 13 ECA 236 cookie example  To use a cookie with a log-in script  display HTML form asking user for her username and password  validate user input to make sure neither field is empty  query database for username and password  if they exist, write necessary cookies, redirect to new page  subsequent pages access cookie values

Open Source Server Side Scripting 14 ECA 236 sessions  sessions are designed to store data on server and client  designed to work with cookies, but will still work without them  4 steps to using sessions  start a session  register session variables  access and use session variables  unset session variables and destroy session

Open Source Server Side Scripting 15 ECA 236 start a session  session_start( )  begin a new session  or access current session  creates a unique session ID  cryptographically created random number  32 hexadecimal values a558b9ac9105eda1432bb254dfa3fe18

Open Source Server Side Scripting 16 ECA 236 start a session cont …  by default, session ID is stored in a cookie  PHPSESSID  session_start( ) must be called before any other data is sent to the browser  if cookies are turned off, we can still use sessions  process is not automatic

Open Source Server Side Scripting 17 ECA 236 session ID  can be passed appended to URL  is stored in a constant named SID  append to URL in header function  embed in links header( “Location: $_SERVER[ ‘HTTP-HOST’ ]. dirname( $_SERVER[ ‘PHP_SELF’ ] ). “file_name.php?”. SID ); echo ‘ page 2 ’;

Open Source Server Side Scripting 18 ECA 236 register session variables  $_SESSION  to access values from a database using mysql_fetch_array( )  sessions can store objects and arrays as well $_SESSION[ ‘first_name’ ] = “Bob”; $_SESSION[ ‘first_name’ ] = $row[ 'first_name' ]; $_SESSION[ ‘last_name’ ] = $row[ ‘last_name' ]; $_SESSION[ ‘username’ ] = $row[ ‘username’ ];

Open Source Server Side Scripting 19 ECA 236 accessing session variables  to access session variables on subsequent pages  reference the current session with session_start( )  use $_SESSION  to test that a variable is registered to the session, use isset( ) $first_name = $_SESSION[ ‘first_name’ ] ;

Open Source Server Side Scripting 20 ECA 236 deleting session variables  delete session variables once the user logs out  unset( )  use to delete individual session variables  to delete every session variable, set $_SESSION array to empty array unset( $_SESSION[ ‘variable_name’ ]; $_SESSION = array( );

Open Source Server Side Scripting 21 ECA 236 destroy session  once the user is finished with a session, end the session  session_destroy( )  destroys the session and the session ID  does not unset any of the session variables  does not unset session cookie

Open Source Server Side Scripting 22 ECA 236 session example  To use a session with a log-in script  start a session with session_start( )  display HTML form asking user for her username and password  validate user input to make sure neither field is empty  query database for username and password  if they exist, register session variables, redirect user to appropriate page  to access session variables, subsequent pages must call session_start( )

Open Source Server Side Scripting 23 ECA 236 session handling functions  changing session configuration settings  session name  cookie lifetime  session maxlife  etc  PHP Manual  XCV. Session Handling Functions