RU beehive logo ITEC dept promo banner
ITEC 325
2011fall
ibarland

homelectsexamshws
breeze (snow day)

lect08-ch09
cookies and sessions
chapter 9

From PHP Visual Quickstart Guide by Larry Ullman
Originally based on notes by Jack Davis (jcdavis@radford.edu)

As larger more complex web sites are being built the limitation of http as a stateless protocol becomes a problem. Web developers have no built in (html) method of remembering data from one page of an application to the next. This is a serious short-coming, e-commerce systems, user registration and login systems, and other online services rely on this functionality. Fortunately, maintaining state from one page to another is fairly simple using PHP.

Self-assessment: Why does the following not print out 2.5?

<?php
  // before any html has been printed:
  setcookie('hamburger-price', 2.50);
  ?>

  &vdots;
  <p>
  The going rate for hamburgers is $<?php printf("%.2f", $_COOKIE['hamburger-price'] ); ?>.
  </p>
 
(More precisely, it may not print out 2.5...) Note that the printf format is fine.

Sessions

homelectsexamshws
breeze (snow day)


©2011, Ian Barland, Radford University
Last modified 2011.Oct.28 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme