Objectives
  • Define and describe state information
  • Use hidden form fields to save state information
  • Use query strings to save state information
  • Use cookies to save state information
  • Use sessions to save state information
Assignments and Due Dates


Assignments and Due Dates: View
CS2623 Coding Standards - requirements for all class assignments

Required Readings

PHP Programming with MySQL //Second Edition by Don Gosselin, et al
Chapter 9 - Managing State Information
Text Resources
     Errata Sheet
     Best Practices

Recommended Tutorials

    Video: Lynda.com: 
    PHP fpr Web Designers by David Powers
    9 . Getting User Input from a Form
         Using PHP Sessions to preserve data (Good overview of hidden fields, cookies, and sessions.
              You might want to view the two that follow this video, but I personally prefer the Skoglund videos)

    PHP with MySQL Essential Training by Kevin Skoglund
    10. Building Web Pages (All videos)
    12. Working with Cookies and Sessions (All videos)
    19. Regulating Page Access (All videos)

 

Sample Code
The sample code is in a file which must be downloaded and extracted to location accessible by the server. Be sure to do this before testing the code.
Supplemental Materials
Some of these items are from last week but included here as a reference
Required Software

PHPMyAdmin and MySQL which was included with your WAMP|MAMP download will be used for work with databases.
Firefox makes viewing cookies very easy. It is recommended that you use it when wanting to check cookie values. It is used by Skoglund in his videos.

Chapter Questions and Test Reviews

Chapter 9: Review Questions (.rtf file)
Test 4: Review Sheet

Required Assignments
  • SSP09: Managing State Information (Complete, upload to Apollo1, then submit URL in the LMS)
  • Weekly Quiz: Chapter 9 (Located in the LMS)
Professor's Class Notes and Comments

IMPORTANT:

The sample code in ManagingState.zip must be downloaded and extracted to location accessible by the server (htdocs or www). These files must be used locally.

A database named maintainstate is used in some of the example. Before reviewing the sample code, import maintainstate.sql into PHPMyAdmin. It will create a database named maintainstate. The database includes one table named users.

The examples are coded to be used on localhost in a Windows environment using WAMP.
$DBConnect = mysqli_connect("localhost", "root", "");
If working on a MAC use the following code:
$DBConnect = mysqli_connect("localhost", "root", "root");
Note: maintainstate.sql has been included in more than one folder. However, it only needs to be imported one time.


Lynda.com Videos

You are welcome to work through the entire CMS creation in the videos. If you choose not to (and that is fine) the videos can provide some very useful information. If you need a further explanation of cookies, supplemental videos have been included in the Supplemental Materials Panel.

Chapter 8

As you may have well discovered by this point in time, the text's examples are often a bit involved for simple concepts. Students have mentioned that they had to dig through code to find the part they really needed. While I think the text examples are helpful, the sample code which I have provided usually are more simplistic. Be sure to give them a look.

p. 506
Hidden fields are not the most popular way to save state. However, they do have their place. For instance Pay Pal uses them to pass nonsensitive information from the shopping cart. Please keep in mind that this is not secure.

Sample Code: SSP_HiddenFields1
                    SSP_HiddenFields2

p. 515
Sample Code: SSP_QueryStrings

  p. 518
  Viewing the content of cookies:

How to View Cookies (upated January 2016) http://www.wikihow.com/View-Cookies
Note: While this appears like it may be a video it is not. Be cautious, clicking on an arrow could start a download or redirect you to anohter web page.

p. 519
First full paragraph: It states that setcookie() must be called before anything is sent to the browser. This is something that is easily overlooked and has caused issues for a number of students

Sample Code: SSP_Cookie_1_Basics
Sample Code: SSP_Cookie_2_Authentication (be sure to view the files in order since some of them require the previous file)

p.530
Sample Code: SSP_Sessions
The server can be set to end a session after a period of inactivity. Usually 20 minutes is the default for most servers.

Appreciate cookies in PHP, they are so, so much easier than in JavaScript...as I am sure some of you will attest to!