Chapter 6. Passing Information with PHP

In this chapter, we'll briefly discuss some things you need to know about passing data between web pages. Some of this information is not specific to PHP but is a consequence of the PHP/HTML interaction or of the HTTP protocol itself.

HTTP Is Stateless

The most important thing to recall about the way the web works is that the HTTP protocol itself is stateless. If you are a poetic soul, you might say that each HTTP request is on its own, with no direction home, like a complete unknown . . . you know how the rest goes.

For the less lyrical among us, this means that each HTTP request — in most cases, this translates to each resource (HTML page, .jpg file, style sheet, and so on) being asked for and delivered — is independent of all the others, knows nothing substantive about the identity of the client, and has no memory.

Even if you design your site with very strict one-way navigation (Page 1 leads only to Page 2, which leads only to Page 3, and so on), the HTTP protocol will never know or care that someone browsing Page 2 must have come from Page 1. You cannot set the value of a variable on Page 1 and expect it to be imported to Page 2 by the exigencies of HTTP itself. You can use HTTP to display a form, and someone can enter some information using it — but unless you employ some extra means to pass the information ...

Get PHP6 and MySQL® 6 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.