Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizards Guide to PHP by David Lash.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

McGraw-Hill©The McGraw-Hill Companies, Inc., 2000 Chapter 22 Simple Mail Transfer Protocol (SMTP)
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
Advanced Piloting Cruise Plot.
Copyright © 2003 Pearson Education, Inc. Slide 6b-1 The Web Wizards Guide to PHP by David Lash.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Copyright © 2003 Pearson Education, Inc. Slide 1-1 The Web Wizards Guide to PHP by David A. Lash.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 6-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
Copyright © 2003 Pearson Education, Inc. Slide 6a-1 The Web Wizards Guide to PHP by David Lash.
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 8 Managing End-User Sessions.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
Chapter 1 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Slide 1 FastFacts Feature Presentation October 24, 2013 To dial in, use this phone number and participant code… Phone number: Participant.
Slide 1 FastFacts Feature Presentation August 14 th, 2008 We are using audio during this session, so please dial in to our conference line… Phone number:
Slide 1 FastFacts Feature Presentation February 17, 2011 We are using audio during this session, so please dial in to our conference line… Phone number:
Slide 1 FastFacts Feature Presentation September 7, 2010 We are using audio during this session, so please dial in to our conference line… Phone number:
Slide 1 FastFacts Feature Presentation September 21, 2010 We are using audio during this session, so please dial in to our conference line… Phone number:
Slide 1 FastFacts Feature Presentation October 12, 2010 We are using audio during this session, so please dial in to our conference line… Phone number:
Slide 1 FastFacts Feature Presentation October 19, 2010 We are using audio during this session, so please dial in to our conference line… Phone number:
1 Advanced with GMail A CYC Electives Module
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
17 Copyright © 2005, Oracle. All rights reserved. Deploying Applications by Using Java Web Start.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
Child Health Reporting System (CHRS) How to Submit VHSS Data
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
Michigan Electronic Grants System Plus
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
ZMQS ZMQS
ABC Technology Project
Vanderbilt Business Objects Users Group 1 Reporting Techniques & Formatting Beginning & Advanced.
©2013 PROS, Inc. All rights reserved. Confidential and Proprietary. PROS Connect User Community Website and Support Portal Prepared by Christine Lambden.
1 ITSS This overview deck contains two sections. Please use the links below to navigate –How to Register for ITSS Application AccessHow to Register for.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
In The Name Of Allah, The Most Beneficent, The Most Merciful
XP New Perspectives on Introducing Microsoft Office 2003 Tutorial 1 1 Using Common Features of Microsoft Office 2003 Tutorial 1.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Customize Your View of Data Training Presentation for Supply Chain Platform: BAE Systems July 2012.
Squares and Square Root WALK. Solve each problem REVIEW:
© 2012 National Heart Foundation of Australia. Slide 2.
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
® Microsoft Office 2010 Browser and Basics.
Week 1.
We will resume in: 25 Minutes.
Chapter 12 Working with Forms Principles of Web Design, 4 th Edition.
How Cells Obtain Energy from Food
CpSc 3220 Designing a Database
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.
Slide 7-1 CHAPTER 7 Managing Multiple-Form Applications: Writing scripts with multiple screens.
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.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
Presentation transcript:

Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizards Guide to PHP by David Lash

Copyright © 2003 Pearson Education, Inc. Slide 7-2 CHAPTER 7 Managing Multiple-Form Applications: Writing scripts with multiple screens

Copyright © 2003 Pearson Education, Inc. Objectives To understand what are multiple-form Web sessions To learn how to use hidden fields to build multiple- form user sessions To learn how to use browser cookies to track data about the user To learn how to use PHP session functions and how to use them to track data about the user

Copyright © 2003 Pearson Education, Inc. Slide 7-4 What Are Multiple-Form Web Sessions? A multiple-form Web session leads the user through a series of HTML forms that work together and pass data from form to form. E.g., a shopping cart or on-line survey.

Copyright © 2003 Pearson Education, Inc. Slide 7-5 Example Multiple Screen Session

Copyright © 2003 Pearson Education, Inc. Slide 7-6 Using Hidden Fields to Pass Data Hidden fields are part of HTML forms Not displayed but value can be accessed in receiving script like any other variable. Can still be viewed by users who view source.

Copyright © 2003 Pearson Education, Inc. Slide 7-7 A Full Script Example Consider an example script sets a hidden field Implements the Order Info form on submit sends data to php

Copyright © 2003 Pearson Education, Inc. Slide 7-8 PHP Script 1. Order Product 2. <form action=" method="post"> 3. Happy Harry's Hardware Product Order Form We have hammers, handsaws, and wrenches on special today! Enter Item: 9. Enter Quantity:

Copyright © 2003 Pearson Education, Inc. Slide 7-9 The Output... The previous code can be executed at

Copyright © 2003 Pearson Education, Inc. Receiving Hidden Fields in Web Sessions Your scripts can receive data from hidden fields like any other data. Suppose the following is stored at:

Copyright © 2003 Pearson Education, Inc. Slide 7-11 Receiving PHP Script 1. Order Product <?php 5. print " "; 6. print "Hidden value=$sample_hidden "; 7. print "You selected product=$product and quantity=$quantity"; 8. print " "; 9. print " "; 10. print " "; 11. print 'Please enter your name:'; 12. print ' '; 13. print ' and billing code: (5 digits)'; 14. print '<input type="text" size="5" maxlength="5" name="code">'; 15. print ' '; 16. print ' '; 17. ?>

Copyright © 2003 Pearson Education, Inc. Slide 7-12 Receiving PHP Script With REGISTER_GLOBALS Off 1. Order Product <?php $sample_hidden = $_POST[sample_hidden]; 5. $product = $_POST[product]; $quantity = $_POST[quantity]; 5. print " "; 6. print "Hidden value=$sample_hidden "; 7. print "You selected product=$product and quantity=$quantity"; 8. print " "; 9. print " "; 10. print " "; 11. print 'Please enter your name:'; 12. print ' '; 13. print ' and billing code: (5 digits)'; 14. print '<input type="text" size="5" maxlength="5" name="code">'; 15. print ' '; 16. print ' '; 17. ?>

Copyright © 2003 Pearson Education, Inc. Slide 7-13 Sending from PHP scripts Sometimes it is useful to send from a PHP script: PHP uses mail() that by default sends via the Simple Mail Transfer Protocol (SMTP). mail(to_address, subject, message, extra_headers); Specify the destination address. Specify the subject line of the . Specify the Text of the Specify additional headers.

Copyright © 2003 Pearson Education, Inc. Slide 7-14 Consider the following example … $subject = 'New Hardware Order'; 3. $message = 'Enclosed is a new order for 12 hammers.\n Thanks.'; 4. $extra = 'From: 5. mail( $dest, $subject, $message, $extra );

Copyright © 2003 Pearson Education, Inc. Slide 7-15 Consider the following full example … Implements save and notify Called from order2.php and saved at webwizard.aw.com/~phppgm/C7/order3.php Can access variables $product, $quantity, and $sample_hidden sent as hidden fields from the Billing Info form.

Copyright © 2003 Pearson Education, Inc. Slide 7-16 The following PHP Script … 1. Order Product 3 2. <?php $body = "New Order: Product=$product Number=$quantity Cust=$name Code=$code"; 5. print ' '; 6. print " Sending to order handling department at $ ... "; 7. print " The body is : $body. "; 8. $from = 9. $subject = "New order from $name"; 10. mail($ , $subject, $body, "From: $from"); 11. print ' sent. Thanks for ordering. '; 12. print " By the way, sample hidden=$sample_hidden"; 13. ?>

Copyright © 2003 Pearson Education, Inc. Slide 7-17 The following PHP Script with REGISTER_GLOBALS Off … 1. Order Product 3 2. <?php 3. $sample_hidden = $_POST[sample_hidden]; quantity=$_POST[$quantity]; 4. $product = $_POST[product]; $name=$_POST[name]; $body = "New Order: Product=$product Number=$quantity Cust=$name Code=$code"; 5. print ' '; 6. print " Sending to order handling department at $ ... "; 7. print " The body is : $body. "; 8. $from = 9. $subject = "New order from $name"; 10. mail($ , $subject, $body, "From: $from"); 11. print ' sent. Thanks for ordering. '; 12. print " By the way, sample hidden=$sample_hidden"; 13. ?>

Copyright © 2003 Pearson Education, Inc. Slide 7-18 Would have the following output …

Copyright © 2003 Pearson Education, Inc. Slide 7-19 Would have the following output …

Copyright © 2003 Pearson Education, Inc. Slide 7-20 Using Browser Cookies … Cookies are small pieces of data that a Web application can save when a user visits the Web page. Stored on the visitors hard drive a Web page script can read the previously stored browser cookie data

Copyright © 2003 Pearson Education, Inc. Slide 7-21 Understanding Cookie Limitations Users can easily disable the cookies feature. People move around. Users may delete cookies. PHP sets limit on cookies

Copyright © 2003 Pearson Education, Inc. Slide 7-22 The disable cookie screen in Netscape

Copyright © 2003 Pearson Education, Inc. Slide 7-23 Setting and Reading Cookies Cookies can be set in memory or on hard disk Set on hard disk are deleted when browser closes Can use the setcookie() script setcookie('Customer_name', 'Denise'); Directs browser to create a cookie Specify the cookies name Specify the cookies value

Copyright © 2003 Pearson Education, Inc. Slide 7-24 Setting A Cookie on a Hard Drive You need to use the time() function when want to set a cookie on a hard drive.

Copyright © 2003 Pearson Education, Inc. Slide 7-25 A full example of setting a cookie…. Suppose a front-end web page asks for some survey information: <input type="radio" name="prefers" value="power tools" checked > Power Tools? <input type="radio" name="prefers" value="hand tools"> Hand Tools? <input type="radio" name="prefers value="air fresheners"> Air Fresheners?

Copyright © 2003 Pearson Education, Inc. Slide 7-26 The following script runs when submitted: 1.<?php 2. $expire = time() + (60 * 60 * 24 * 30); 3. setcookie("name", $custname, $expire); 4. setcookie("preference", $prefers, $expire); 5.?> Happy Harry's Hardware Catalog 8. 9.<?php 10. print "Thanks $custname! ; 11. print Lets now look at $prefers... "; 12.?>

Copyright © 2003 Pearson Education, Inc. Slide 7-27 The following script runs when submitted: (With REGISTER_GLOBALS Off). 1.<?php $prefers = $_POST[prefers]; $expire=$_POST[expire]; $custname=$_POST[custname]; 2. $expire = time() + (60 * 60 * 24 * 30); 3. setcookie("name", $custname, $expire); 4. setcookie("preference", $prefers, $expire); 5.?> Happy Harry's Hardware Catalog 8. 9.<?php 10. print "Thanks $custname! ; 11. print Lets now look at $prefers... "; 12.?>

Copyright © 2003 Pearson Education, Inc. Slide 7-28 Would output:

Copyright © 2003 Pearson Education, Inc. Slide 7-29 Reading Cookies You can read a cookie by using a variable name with the same name as a cookie: print $cust_name;

Copyright © 2003 Pearson Education, Inc. Slide 7-30 Reading Cookies with REGISTER_GLOBALS Of To read a cookie value use the $_COOKIE[] associative array to get the cookie function $cust_name= $_COOKIE[cust_name];

Copyright © 2003 Pearson Education, Inc. Slide 7-31 Example Script that read a cookie Happy Harry's Hardware Catalog 3. 4.<?php 5. print ' '; 6. if (isset($name)){ 7. print "Welcome back to our humble hardware site, $name."; 8. } else { 9. print ' '; 10. print 'Welcome to our humble hardware site. '; 11. } 12. if ($preference == 'hand tools'){ 13. print ' We have hammers on sale for 5 dollars!'; 14. } elseif ($preference == 'power tools'){ 15. print ' We have power drills on sale for 25 dollars!'; 16. } elseif ( $preference == 'air fresheners'){ 17. print ' We now carry extra-strength air fresheners!'; 18. } else { 19. print ' '; 20. print 'We have drills and hammers on special today!'; 21. } 22. ?>

Copyright © 2003 Pearson Education, Inc. Slide 7-32 Example Script that read a cookie Happy Harry's Hardware Catalog 3. 4.<?php $name = $_COOKIE[name]; $preference = $_COOKIE[preference]; 5. print ' '; 6. if (isset($name)){ 7. print "Welcome back to our humble hardware site, $name."; 8. } else { 9. print ' '; 10. print 'Welcome to our humble hardware site. '; 11. } 12. if ($preference == 'hand tools'){ 13. print ' We have hammers on sale for 5 dollars!'; 14. } elseif ($preference == 'power tools'){ 15. print ' We have power drills on sale for 25 dollars!'; 16. } elseif ( $preference == 'air fresheners'){ 17. print ' We now carry extra-strength air fresheners!'; 18. } else { 19. print ' '; 20. print 'We have drills and hammers on special today!'; 21. } 22. ?>

Copyright © 2003 Pearson Education, Inc. Slide 7-33 PHP Sessions PHP supports two functions that enable you to retain data between forms session_start() - either starts a new session or resumes one if a session exists Run at the start of every script By default creates a unique session ID stored as a cookie session_register() - registers one or more variables as session variables $name = 'Matthew'; $preference = 'Soccer Equipment'; session_register('name', 'preference');

Copyright © 2003 Pearson Education, Inc. Slide 7-34 Example PHP Code Order Product 3. 4.<form action= " method="post"> 5. Hardware Product Order Form 6. We have hammers, handsaws, and wrenches. 7. Enter Item: 8.Enter Quantity: 9.<?php 10. $sample_hidden='Welcome Again!'; 11. session_register('sample_hidden'); 12.?>

Copyright © 2003 Pearson Education, Inc. Slide 7-35 Example output This script can be executed at:

Copyright © 2003 Pearson Education, Inc. Slide 7-36 Use the following script to read the session data Order Product <?php 6. print " Sample hidden= $sample_hidden "; 7. print " You selected product=$product and quantity=$quantity"; 8. session_register('product', 'quantity'); 9. print ' Please enter your name'; 10. print ' '; 11. print ' and Billing Code: (5 digits)'; 12. print ' '; 13. print ' '; 14. print ' '; 15. print ' '; 16.?>

Copyright © 2003 Pearson Education, Inc. Slide 7-37 Example output This script can be executed at:

Copyright © 2003 Pearson Education, Inc. Slide 7-38 Some session extras session_is_registered() - can be used to determine if a variable comes from a session: if (session_is_registered('name')){ print "got name=$name from session"; } else { print "name=$name not set from session"; }

Copyright © 2003 Pearson Education, Inc. Slide 7-39 Session Extras - $_SESSION Use $_SESSION Associative array when REGISTER_GLOBALS are off in php.ini Do not need to use session_register() session_start(); $_SESSION['sample_hidden'] = 'Welcome!';

Copyright © 2003 Pearson Education, Inc. Slide 7-40 Summary Hidden fields are HTML form fields you can use to set a variable name and variable value without displaying them on a form. Cookies provide a way for Web server applications to store small pieces of data on the users hard disk. PHP session functions provide a convenient way to retain data between PHP scripts. Use session_start() and session_register() functions to start sessions and define session variables, respectively