RU beehive logo ITEC dept promo banner
ITEC 325
2012spring
ibarland

homelectsexamshws
D2Lbreeze (snow day)

lect09a-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.50?

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

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

Sessions

homelectsexamshws
D2Lbreeze (snow day)


©2012, Ian Barland, Radford University
Last modified 2012.Mar.26 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme