PHP's session

PHP's session allows to store vital browser information visiting a web site in a browser's session. This is done in PHP using session_start() method. Each page that relies on session information need to use this functionality, therefore it is a good idea to handle the session by a separate file that is referred by every web site page that relies on session data. Session information is stored in browser memory therefore it can be considered secure.

What information can be stored in session?

- Web site user name.

- Web site login state.

Information is written to a session using keyword $_SESSION, followed by name of the property in square brackets. This name of session variable also must be included in quotes. This must be followed by equal sign and the data that needs to be stored in session. 

Once session data is written, session needs to be closed by session_write_close() statement.

Session data can be retrieved by using keyword $_SESSION that follows name of a session variable. Session variable needs to be put in square brackets and quotes.

Browser session can be cleared by using session_destroy() method. It will clear all of the content of the PHP's session.

Each request to web page is session less, storing vital information in browser's session variables overcomes that limitation.

Even so, it is possible to store browser's information in a cookie, cookie's information should not be considered secure.


Comments

Popular posts from this blog

Absolute and relative path in HTML pages

Errors

goto PHP operator