|[ Team LiB ]|
In this hour and the previous hour, you learned different ways of saving state in a stateless protocol. All methods use some combination of cookies and query strings, sometimes combined with the use of files or databases. These approaches all have their benefits and problems.
A cookie is not intrinsically reliable and cannot store much information. On the other hand, it can persist over a long period of time.
Approaches that write information to a file or database involve some cost to speed that might become a problem on a popular site. Nonetheless, a simple ID can unlock large amounts of data stored on disk.
A query string is unlikely to persist as a cookie will and looks ugly in the location window. Even so, it can pass relatively large amounts of information from request to request. The choice you make depends on the circumstances of your project.
In this hour, you learned how to initiate or resume a session with session_start(). Once in a session, you can register variables with it using the $_SESSION array and access session elements from request to request. You should be able to destroy a session with session_destroy().
To ensure that as many users as possible get the benefit of your session-enabled environment, you can now use the SID constant to pass a session ID to the server as part of a query string.
In the next hour, you examine ways that you can use PHP to access other tools on your server.
|[ Team LiB ]|