1 Chapter 9 – Cookies, Sessions, FTP, Email and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.

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.
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.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Chapter 10 Managing State Information Using Sessions.
©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.
Php cookies & sessions.
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.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
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.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
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.
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.
Website Development with PHP and MySQL Saving Data.
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 Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
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.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Sessions Brendan Knight A visitor accessing your web site is assigned a unique id. This id links to specific data that remains on the server. Sessions.
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.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
PHP – Hypertext Preprocessor.
© 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.
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
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.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
ITM 352 Cookies.
Cookies and Sessions in PHP
Implementing Cookies in PHP
<?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.
Web Programming Language
Cookies and Sessions.
PHP-II.
[Based in part on SWE 432 and SWE 632 materials by Jeff Offutt, GMU]
Presentation transcript:

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 and Technology Radford University

2 PHP Sending The PHP installation has to include some specifications for how to send , in particular the PHP initialization file must specify the connections to the system. At RU, this has been done. To send in a PHP script use the mail function. Mail(string to, string subject, string message, [,string additional_headers [, string additional_parameters]]) This sends an to the address in to, with subject subject and message message. You can also set additional mail headers and parameters to mail. $result = “Web mail”, $_REQUEST[“message”]); **message is retrieved from html form

3 PHP w/Headers (mailinput.php)mailinput.php Additional headers like the following may be specified. cc (“carbon copy”) bcc (“blind carbon copy”) These are set with the additional_headers parameter. $headers.= “cc:”. $_REQUEST[“cc”]. “\r\n”; $headers.= “bcc:”. $_REQUEST[“bcc”]. “\r\n”; $result = “Web mail”, $_REQUEST[“message”], Can also send with attachments.

4 PHP Cookies Cookies hold text that you can store on the user’s computer and retrieve later. They are set using the setcookie function. setcookie parameters: name - cookie name value - value to be stored on the client machine expire - time the cookie expires, set with PHP time function (1/1/70) path - path on the server on which the cookie will be available domain - domain for which the cookie is available secure - indicates that the cookie should only be transmitted via https.

5 PHP Cookies Cookies are part of the HTTP headers sent to the browser, and so they must be sent before any other output from the PHP script. Calls to this function must occur before any other output from your script. This means calls to setcookie must occur before any other output including and tags. If some output exists before calling this function, setcookie may fail and return FALSE. …

6 Getting Cookies After a cookie is set, it won't be visible to scripts until the next time a page is loaded. The cookie is sent from the server machine, so it won't be sent from the client to the server until the next time a request is sent by the client. Cookies are sent in the HTTP headers to the server from the client, then only if the request is for a page from the same domain that the cookie came from. After cookies are set, they can be accessed on the next page load with $_COOKIE array. Say a previous page set a cookie named message. Then it will be in the global array $_COOKIE. So, in the PHP script we have only to access the $_COOKIE array, however, we should check to see the cookie exists. if (isset($_COOKIE['message'])) { echo $_COOKIE['message']; }

7 COOKIE Arrays Cookie names can also be set as array names and will be available to your PHP scripts as arrays. For example: setcookie("cookie[one]","no"); setcookie("cookie[two]","worries"); setcookie("cookie[three]","today."); After these cookies have been set, they could be read after the next request like this: if (isset($_COOKIE['cookie'])) { foreach ($_COOKIE['cookie'] as $data) { echo "$value "; } }

8 Cookie Expiration Time You can also specify how long the cookie should exist on the user's machine. The cookie will be deleted when the user ends the current browser session (which usually means closing all browser windows). So, normally we'll want to specify how long a cookie should last by giving a value for the expire parameter. Normally, we use the time function which returns current time, then add the number of seconds we want the cookie to last. setcookie("mycookie", $value, time() ); How long will this cookie last? Delete a Cookie just set the cookie's value to "" and call setcookie with the same parameters as the cookie was set with. When the value argument is set to an empty string, and all other arguments match a previous call, then the cookie will be deleted from the user's machine.

9 PHP Sessions When clients are working with various pages in your web application, all the data in the various pages is reset to its original values when those pages are loaded. That means all the data is reinitialized between accesses. There are times when you want to retain data from a single client longer. To do this you can use cookies, hidden fields, or session variables. Sessions are designed to hold data on the server. Each user is given a cookie with his or her session ID, which means that PHP will be able to reinstate all the data in each user's session automatically, even over multiple page accesses. If the user has cookies turned off, PHP can encode the session ID in the URL.

10 PHP Sessions (cont.) Using sessions, you can store and retrieve data by name. To work with a session, you start by calling session_start. To store data in the session, you use the $_SESSION array. session_start(); $_SESSION['color'] = "blue"; in a separate page you might: session_start(); $color = $_SESSION['color']; Session behavior is affected by many settings when PHP is installed. For example, session variable life is limited to the number of minutes specified for session.cache_expire, which can only be set during the PHP install. All data for a particular session will be stored in a file in the directory specified by the session.save_path item in the php.ini file. A file for each session will be created.