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

Slides:



Advertisements
Similar presentations
Powerpoint Templates Page 1 Powerpoint Templates Server Side Scripting PHP.
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.
Cookie in a servlet. Cookies are small bits of textual information that a Web server sends to a browser and that the browser returns unchanged when visiting.
©2009 Justin C. Klein Keane PHP Code Auditing Session 7 Sessions and Cookies Justin C. Klein Keane
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.
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.
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.
JavaScript, Fourth Edition
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
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.
Creating Databases for Web Applications cookie examples lab time: favorites cookies & Sessions class time for group work/questions on projects Next class:
Chapter 8 Cookies And Security JavaScript, Third Edition.
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.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
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
PHP Workshop ‹#› Maintaining State in PHP Part II - Sessions.
SessionsPHPApril 2010 : [‹#›] Maintaining State in PHP Part II - Sessions.
Dynamic Programming with PHP (mktime), Cookies, SQL, Authentication.
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.
Lecture 7 Maintaining State (cookies & sessions) & MySQL Interaction (revisited)
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
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.
IS2802 Introduction to Multimedia Applications for Business Lecture 8: JavaScript and Cookies 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.
©SoftMooreSlide 1 Cookies. ©SoftMooreSlide 2 Cookies Basic idea –web application sends a simple name/value pair to the client –when the client connects.
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 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.
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
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.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
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
The need for persistence Consider these examples  Counting the number of “hits” on a website  i.e. how many times does a client load your web page source.
Cookies Tutorial Cavisson Systems Inc..
Managing State Chapter 13.
CSE 154 Lecture 20: Cookies.
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.
Sessions and cookies (part 2)
Maintaining State in PHP Part II - Sessions
Client / Session Identification Cookies
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
CSc 337 Lecture 27: Cookies.
Cookies and Sessions.
Web Programming Language
CSc 337 Lecture 25: Cookies.
Presentation transcript:

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

CookiesPHPMay-2007 : [‹#›] xHTML - a ‘stateless’ environment stateless (adj.) Having no information about what occurred previously. Most modern applications maintain state, which means that they remember what you were doing last time you ran the application, and they remember all your configuration settings. This is extremely useful because it means you can mould the application to your working habits. Each request for a new web page is processed without any knowledge of previous pages requested or processed.

CookiesPHPMay-2007 : [‹#›] How do they do that? For example: A user ‘logs in’ to a web page. Once logged in, the user can browse the site while maintaining their logged in state.

CookiesPHPMay-2007 : [‹#›] Is PHP stateless? Variables are destroyed as soon as the page script finishes executing. The script can access the ‘referrer’, the address of the previous page, although this can’t really be trusted. $_SERVER['HTTP_REFERER'] It is possible to add data to a database/text file to add persistent data, although this is not connected with a particular user…

CookiesPHPMay-2007 : [‹#›] Is PHP Stateless… No! The usual way to maintain state in PHP pages is via the use of Sessions. To understand how these work, we need to have a look at what and how cookies are..

CookiesPHPMay-2007 : [‹#›] What is a Cookie? A cookie is a small text file that is stored on a user’s computer. Each cookie on the user’s computer is connected to a particular domain. Each cookie be used to store up to 4kB of data. A maximum of 20 cookies can be stored on a user’s PC per domain.

CookiesPHPMay-2007 : [‹#›] Example (1) 1. User sends a request for page at for the first time. page request

CookiesPHPMay-2007 : [‹#›] Example (2) 2. Server sends back the page xhtml to the browser AND stores some data in a cookie on the user’s PC. cookie data xhtml

CookiesPHPMay-2007 : [‹#›] Example (1) 3. At the next page request for domain all cookie data associated with this domain is sent too. page request cookie data

CookiesPHPMay-2007 : [‹#›] Set a cookie setcookie(name [,value [,expire [,path [,domain [,secure]]]]]) name = cookie name value = data to store (string) expire = UNIX timestamp when the cookie expires. Default is that cookie expires when browser is closed. path = Path on the server within and below which the cookie is available on. domain = Domain at which the cookie is available for. secure = If cookie should be sent over HTTPS connection only. Default false.

CookiesPHPMay-2007 : [‹#›] Set a cookie - examples setcookie(‘name’,’Robert’) This command will set the cookie called name on the user’s PC containing the data Robert. It will be available to all pages in the same directory or subdirectory of the page that set it (the default path and domain ). It will expire and be deleted when the browser is closed (default expire ).

CookiesPHPMay-2007 : [‹#›] Set a cookie - examples setcookie(‘age’,’20’,time()+60*6 0*24*30) This command will set the cookie called age on the user’s PC containing the data 20. It will be available to all pages in the same directory or subdirectory of the page that set it (the default path and domain ). It will expire and be deleted after 30 days.

CookiesPHPMay-2007 : [‹#›] Set a cookie - examples setcookie(‘gender’,’male’,0,’/’) This command will set the cookie called gender on the user’s PC containing the data male. It will be available within the entire domain that set it. It will expire and be deleted when the browser is closed.

CookiesPHPMay-2007 : [‹#›] Read cookie data All cookie data is available through the superglobal $_COOKIE : $variable = $_COOKIE[‘cookie_name’] or $variable = $HTTP_COOKIE_VARS[‘cookie_name’]; e.g. $age = $_COOKIE[‘age’]

CookiesPHPMay-2007 : [‹#›] Storing an array.. Only strings can be stored in Cookie files. To store an array in a cookie, convert it to a string by using the serialize() PHP function. The array can be reconstructed using the unserialize() function once it had been read back in. Remember cookie size is limited!

CookiesPHPMay-2007 : [‹#›] Delete a cookie To remove a cookie, simply overwrite the cookie with a new one with an expiry time in the past… setcookie(‘cookie_name’,’’,time()-6000) Note that theoretically any number taken away from the time() function should do, but due to variations in local computer times, it is advisable to use a day or two.

CookiesPHPMay-2007 : [‹#›] To be first.. HEADER REQUESTS As the setcookie command involves sending a HTTP header request, it must be executed before any xhtml is echoed to the browser, including whitespace. correct! incorrect. echoed whitespace before setcookie

CookiesPHPMay-2007 : [‹#›] Malicious Cookie Usage There is a bit of a stigma attached to cookies – and they can be maliciously used (e.g. set via 3 rd party banner ads). The important thing to note is that some people browse with them turned off. e.g. in FF, Tools > Options > Privacy

CookiesPHPMay-2007 : [‹#›] The USER is in control Cookies are stored client-side, so never trust them completely: They can be easily viewed, modified or created by a 3 rd party. They can be turned on and off at will by the user.

CookiesPHPMay-2007 : [‹#›] HOE 13 Using Cookies