How to use session in PHP

I this article I am going to explain about PHP session.
  • 1901

PHP Session

A session allow you to store user information on the server to used across multiple pages or for later use.


Syntax of  a session

<?php

 session_start();

 ?>

Example of  creating  session

<html>

<body>

<?php

 session_start();

 $_SESSION['val1']='one';

 $_SESSION['val2']='two';

 $_SESSION['val3']='three';

 print "All value is stored in session";

 ?>

</body>

</html>


Output:

creating session.jpg

Example of retrieve a session value
 

<html>

<body>

<?php

session_start();

Print_r ($_SESSION);

?>

</body>

</html>

 

Output:

seesion 222.jpg
Example of destroying a session value

 

<html>

<body>

<?php

session_start();

 

session_destroy();

echo" All session has destroyed"."</br>";

 

echo " After destroying all session ,the value is"."</br>";

Print_r ($_SESSION);

 

?>

</body>

</html>


Output:

destroy session.jpg
You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.