Working with the Query String

The great drawback of the cookie is its dependence on the client. Not only are you at the mercy of the user, who might choose not to allow cookies, but you must also rely on the browser’s implementation of the standard. Some browsers have documented bugs concerning the way they deal with cookies. If you want to save state only for a single session, you might decide to use a more traditional approach.

When you submit a form using the GET method, its fields and values are URL encoded and appended to the URL to which the form is sent. They then become available to the server and your scripts. Assuming a form with two fields, user_id and name, the query string should end up looking something like the following:

 http://p24.corrosive.co.uk/qstring.php?name=344343&user_id=matt+zandstra ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition 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.