PHP Session

In PHP Session, information or data is stored on the server side. Each session is associated with sessionID. PHP Session is created using $_SESSION variable and start with session_start() function. Session also overcomes many drawbacks related with the Cookies like Cookies are not much secure as using form data and query strings.

Any hacker can easily change a cookie's contents in order to destroy your application and even affect your hardware badly while in case of a session, SIDs generated by PHP are unique and impossible to guess or access and hence it is very difficult for a hacker to access and affect the session data. You can store more data in a session as compared to a cookie.

How to Create a PHP Session

Syntax

Set the Variable in a PHP Session

Syntax

Set PHP Variable in Session Example

Display Value of Variable in a PHP Session

Syntax

Display Session Variable Value Example

This will produce following result

Change Value of Variable in a PHP Session

Syntax:

Change Value of Variable in a Session Example

This will produce following result

Remove Variables in a PHP Session

Syntax

Remove Variables in a Session Example

Destroy a Session

Syntax

Destroy a Session Example