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.

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

PHP I.
CookiesPHPMay-2007 : [‹#›] Maintaining State in PHP Part I - Cookies.
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.
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.
Chapter 10 Managing State Information PHP Programming with MySQL.
Session Management A290/A590, Fall /25/2014.
Chapter 10 Maintaining State Information Using Cookies.
Objectives Learn about state information
 A cookie is a piece of text that a Web server can store on a user's hard disk.  Cookie data is simply name-value pairs stored on your hard disk by.
PHP: Introduction By Trevor Adams.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
1 Forms for the Web Tom Muck
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
INTERNET APPLICATION DEVELOPMENT For More visit:
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.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
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.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
JavaScript, Fourth Edition
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
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.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Chapter 6 Server-side Programming: Java Servlets
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.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
Cookies & Session Web Technology
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
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.
PHP Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
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
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
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.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
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.
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.
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
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.
Web Programming Language
PHP Forms and Databases.
PHP-II.
Presentation transcript:

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 Sessions

Persistence – What is it? Broadly, it is a any mechanism that allows values from one page activity to be available on the next

Persistence – State Management So why do we need it? HTTP has no way of tracking a user’s visit to a web site HTTP simply responds to requests for resources Web applications demand more functionality than simple, static web pages can provide Data driven web sites often provide access to relatively sensitive data

Persistence – form fields Hidden form fields provide a simple way to maintain application state Simple to use HTML Generated by PHP statements Provides a useful way of processing data differently from one form. E.g. Editing and Adding a record can use the same form The action required can be determined from a hidden field named action The script that catches the post can query action and act appropriately

Persistence – Form fields Form fields have their disadvantages Have to be managed by the programmer Can be laborious on many forms Data has to be obfuscated if sensitive This is not ideal Remember – HTML is plain text Have to be sent to the server each round trip

Persistence – Query Strings Query allow the passing of variables through the URL E.g. Multiple variables are declared using the ampersand (&) character E.g. /product.php?id=1001&order=asc Values can be accessed using the $_GET array This is used similar to the $_POST array E.g. from above example // prints 1001

Persistence – Query Strings Query strings are perfect for bookmarks They are part of the URL Can be given as direct links Query strings can persist through basic HTML elements E.g. Hyperlinks ( )

Persistence – Query Strings Query strings are not ideal in every situation All variables are visible in the URL Useless for sensitive data Some applications specific a 256 character URL limit (including the page) Easy target for unscrupulous people Useless for large input, such as web mail

Persistence – Basic Summary We can create persistent applications using skills we have already covered Hidden form elements Work just like other form elements They do not render on screen Query strings Append key=value pairs to a URL Accessible as $_GET array Visible in the URL

Persistence – Cookie time! Quick (perhaps dirty) way of persisting data using the client Can store data between visits to a site Stored as basic text files on the client machine Cookie data is sent to the server with each page request (providing the cookie is valid)

Persistence - Cookies Cookies have a bad reputation Over used Abused In general people do not trust cookies Often they do not know they are needed for the cool things they enjoy on a web site Possible poor use of cookies include: Tracking and reporting browsing habits Reporting products of interest to other web sites Many others

Persistence - Cookies Cookies should be used for the “Bells and Whistles” of a web site A web site should generally (try to at least) not rely on cookies to be completely functional For example, storing the user’s visual style preference If the cookie is not accepted, the site will still work

Persistence - Cookies PHP allows the programmer to set cookies The setcookie() function This function takes up to 6 parameters Name – required Value – required Expire – time in seconds that the cookie expires Path – path that the cookie is valid for (/tja1) Domain – domain that is valid (e.g. example.web) Secure – whether it requires HTTPS or not setcookie(“cssfile”, “style.css”, time()+1800);

Persistence – Cookie expiration The PHP time() function returns the current time measured in the number of seconds since the Unix Epoch (January :00:00 GMT). Try time() will expire the cookie in 30 minutes 60 seconds * 30 = 1800 We shall cover time and date functions in lab session

Persistence - Cookies Cookies are available on the subsequent page request from when they are set They are accessible via $_COOKIES array The cookie name is the array key Adding values directly to the cookie array will not create a cookie Must use set cookie function for this

Persistence - Cookies Calls to setcookie() must be called before any out put is sent to the browser Cookies are sent in the HTTP header <?php echo “Hello!”; setcookie(“style”, “myfile.css”, time()+1800); ?> Results in an error Output includes any data, including plain HTML that comes before the setcookie() call Do not store arrays in cookie variables They require special manipulation Stick to basic types, textual/numeric

Persistence – Cookie Summary Cookies are great for the ‘nice’ features Do not rely on them Not even in closed environments They are stored on the client Not stored securely Sent with each page request Can be transmitted securely

Persistence - Sessions Sessions are stored on the server Exist for the time a user starts to use your application to the time they finish Or you programmatically end the session (logout) Sessions are very simple to use PHP4 has built in functionality for sessions

Sessions – in use Call the function session_start(); before any output is sent to the browser $_SESSION array is used to store session variables Adding values to $_SESSION will automatically persist those values at the server side

Sessions – in use <?php session_start(); $_SESSION[“uname”] = “tja1”; ?> Subsequent page access <?php Session_start(); Echo $_SESSION[“uname”]; // prints “tja1” ?>

Sessions – Why use them? Store more complex data, such as arrays, easily Data is never involved in a round trip In some ways, more secure Although has security issues of a different nature Well out of the scope of this module

Sessions - Summary Persistence data Maintained on the server Needs to be initialised before output Allows the programmer to implement complex application functionality Probably the best choice to facilitate logins

Topics covered - summary Basic Persistence Query Strings Hidden form elements Cookies Client side storage Sent on every page request Not secure Access using $_COOKIES Sessions Server side variable storage Accessed using $_SESSIONS Avoids the client side storage Still suffers from server side attacks

Resources Use the PHP web site Search for time Search for session_start Search for setcookie