PHP - Sessions Flashcards
HTTP is a ______ _______; a communication protocol in which each new request cannot be linked to any previous requests.
HTTP is a Stateless Protocol; a communication protocol in which each new request cannot be linked to any previous requests.
But a client’s “session” with the server usually contains multiple HTTP requests. (e.g. ______)
But a client’s “session” with the server usually contains multiple HTTP requests. E.g. Shopping on Amazon, Browsing SLATE, etc.
The server can’t tell just by looking at the requests which ones go together. So, even if the same client requested different resources, the server wouldn’t know that they came from the ____ ____.
The server can’t tell just by looking at the requests which ones go together. So, even if the same client requested different resources, the server wouldn’t know that they came from the same client.
PHP Sessions address this issue, thereby allowing us to persist information across multiple requests.
If SLATE did not use sessions, a user would need to log in _____ _____ he/she requests a page.
PHP Sessions address this issue, thereby allowing us to persist information across multiple requests.
If SLATE did not use sessions, a user would need to log in every time he/she requests a page.
The server creates a ____ ______ when a session is started.
The server creates a unique identifier when a session is started.
The server stores this ______. This identifier will now _______ any session variables.
The server stores this identifier. This identifier will now reference any session variables.
The server sends that _______ to the client.
The server send that identifier to the client.
The client stores this identifier in a _______ (a form of storage on the client) and then provides the identifier with ________ requests.
The client stores this identifier in a cookie (a form of storage on the client) and then provides the identifier with subsequent requests.
When needed, the server would use the identifier (now sent with every request) and look for associated _______ data on the server.
When needed, the server would use the identifier (now sent with every request) and look for associated session data on the server.
The server script can now use the session variables found.
The server script can now use the session variables found.
How do I use it? (sessions)
1) Start the session
2) uses the $_SESSION associative array to read or write variables
3) That’s it! Remember to always start the session at the top of the page.
4) When you no longer need the session, use session_destroy()
5) The example below shows how we can retrieve a session variable across multiple requests.
page1.html
Name:
page2.php
<a>page3</a>
page3.php
<a>logout</a>
logout.php (destroying sessions)