IS 337: Website Administration

Lecture for November 5: PHP Arrays, Sessions

+
-

Topics

Getting onto Yardley

  • Set your passwords on the Linux side of the GLUW lab so that Fife won't hunt you down.
  • Fife will run a password cracker, and he will ban you from yardley if your password stinks.

By the Way...

  • isset() for detecting HTTP parameters
  • unset() to unset variables and array elements
  • print_r() to recursively print any object (for debugging)

PHP Arrays

  • Technically: an array is an "ordered map"
  • array() language construct
  • keys must be integers or strings
  • [] syntax
  • foreach loop

Abstraction

  • It's magic!
  • Allows you to ignore many (interesting) details.
  • Examples: Frens's view of networks; PHP sessions.

Sessions

  • Important PHP code toggle
    • session_start() required on each page to access session
    • $_SESSION superglobal
  • Session id can be passed in a cookie or in the URL.
  • Best practices toggle
    • Session abstraction allows the system to store the sessions anywhere: in cookies, on the filesystem, in a database.
    • Store minimal data to lookup in your database.

Security

  • Enter a name that would cause problems.
  • htmlspecialchars()

Readings and Resources

Quick Written Assignment for Next Time

Write a PHP function that uses a foreach loop to print each key-value pair from the $_SESSION array.

Creative © 2007 Calvin College and Jeremy D. Frens.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.