Friday 7 October 2016

PHP sessions


A session is a way to store information to be used across multiple pages.

Session means give a proper time duration for an application, and after that it ends automatically.


We all know that internet don’t know who you are and what application you want to start, when you start application and when you end this application.
Then in that case we use sessions that help server to know about when we end this application. With the help of sessions, we set time duration how many time this application run on server. When session expire, it end the running application on server. It solve the HTTP problem.


session_start() function is used to start a PHP session.

We can start PHP session, for example :

<?php
session_start();
?>

Session variables are set with the PHP Global variable : $_SESSION.





<?php
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>




Session Modification : We can modify a PHP session variable, to change a session variable or just overwrite it.

$_SESSION["favcolor"] = "yellow";

Destroy a session : To remove a session variable or global variable in session, we can use
session_unset() and session_destroy() function.