Chapter 12 Cookies and Sessions Part 1. Stateless Protocol Hypertext Transfer Protocol (HTTP) is stateless No shopping cards No logging.

Slides:



Advertisements
Similar presentations
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Advertisements

PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
PHP Week 11 INFM 603. Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not.
Servlets and a little bit of Web Services Russell Beale.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
How the web works: HTTP and CGI explained
1 The World Wide Web Architectural Overview Static Web Documents Dynamic Web Documents HTTP – The HyperText Transfer Protocol Performance Enhancements.
Chapter 10 Maintaining State Information Using Cookies.
Objectives Learn about state information
15. User Authentication, Form Validation, Paging. M. Udin Harun Al Rasyid, S.Kom, Ph.D
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
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 Part 2. Setting Cookie Parameters setcookie(name, value, expiration, path, host, secure, httponly) epoch – midnight on.
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.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
Week 9 PHP Cookies and Session Introduction to JavaScript.
SHOPPING CARTS CHAPTER 19. E-COMMERCE Typically, an e-commerce site will have public pages and admin pages.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
12/3/2012ISC329 Isabelle Bichindaritz1 PHP and MySQL Advanced Features.
Chapter 9 Using PHP with MySQL. header.html Script 9.1 on page 266 des/header.html
Multifarious Project A personal -system Team Members Abdullah Alghamdi Metaib Alenzai Mohammed Alshehri Hamd Alshamsi.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Nic Shulver, Introduction to Sessions in PHP Sessions What is a session? Example Software Software Organisation The login HTML.
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.
Cookies & Session Web Technology
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
PHP Workshop ‹#› Maintaining State in PHP Part II - Sessions.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
SessionsPHPApril 2010 : [‹#›] Maintaining State in PHP Part II - Sessions.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with 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.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
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.
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.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
PHP Secure Communications Web Technologies Computing Science Thompson Rivers University.
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.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.
MySQL MySQL and PHP – interacting with a database.
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.
COOKIES AND SESSIONS.
LOGIN FORMS.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Chapter 9 Using PHP with MySQL.
Web Design and Development
Maintaining State in PHP Part II - Sessions
Cookies and Sessions in PHP
Cookies BIS1523 – Lecture 23.
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.
Web Systems Development (CSC-215)
Sessions and cookies (part 1)
Chapter 13 Security Methods Part 1.
Cookies and Sessions Part 2
Maintaining State in PHP Part II - Sessions
Web Programming Language
Using PHP with MySQL Part 3
Presentation transcript:

Chapter 12 Cookies and Sessions Part 1

Stateless Protocol Hypertext Transfer Protocol (HTTP) is stateless No shopping cards No logging

Cookies & Session Cookies – Store data in the user’s browser Session – Store data on the server – More secure

Example includes/login_page.inc.php – Displays errors – Display form and calls login.php on submit Script 12.1 on page 369 Purpose: Login form

Example includes/login_functions.inc.php – function redirect_user($page=‘index.php’) – function check_login($dbc, $ , $pass) Script 12.2 on pages Purpose: Validation of login

Example login.php – If form is submitted require ('includes/login_functions.inc.php'); check_login($dbc, $ , $pass) – Set cookies – Redirect to loggedin.php – include login_page.inc.php Script 12.3 on pages 378 Purpose: User interface – Central manager

Example loggedin.php – If (cookies are not set) Redirect to login.php – Welcome page – Link to logout Script 12.4 on page 381 Purpose: Page when logged in

Example logout.php – If (cookies are not set) Redirect to index.php – Delete cookies Script 12.6 on page 385 Purpose: Page when logged out

login.php Script 12.3 on pages ogin.php ogin.php ch12\script_12_03\login.php

login.php list ($check, $data) = check_login($dbc, $_POST[' '], $_POST['pass']); if ($check) { // OK! // Set the cookies: setcookie ('user_id', $data['user_id']); setcookie ('first_name', $data['first_name']); // Redirect: redirect_user('loggedin.php');

function check_login Script 12.2 on pages ch12\login_functions.inc.php

function check_login $q = "SELECT user_id, first_name FROM users WHERE ='$e' AND pass=SHA1('$p')"; $r ($dbc, $q); // Run the query. // Check the result: if (mysqli_num_rows($r) == 1) { // Fetch the record: $row = mysqli_fetch_array ($r, MYSQLI_ASSOC); // Return true and the record: return array(true, $row);

function check_login return array(false, $errors);

function redirect_user Script 12.2 on pages ch12\login_functions.inc.php

login_page.inc.php Script 12.1 on page 369 ch12\login_page.inc.php

loggedin.php Script 12.4 on page 381 ch12\script_12_04\loggedin.inc.php echo " Logged In! You are now logged in, {$_COOKIE['first_name']}! Logout ";

logout.php Script 12.6 on page 385 ch12\script_12_06\logout.php // Delete the cookies: setcookie ('user_id', '', time()-3600, '/', '', 0, 0); setcookie ('first_name', '', time()-3600, '/', '', 0, 0);