PHP list all session variables


 

PHP list all session variables

In this part of the tutorial we will learn how to get all session variable and its values. And we will also see the example related to the session.

In this part of the tutorial we will learn how to get all session variable and its values. And we will also see the example related to the session.

  • All session variables and its values are maintained by the the super global variable $_SESSION.
  • $_SESSION is an associative array. It keeps the session data in key and value form.
  • session_start() starts the session.
  • After execution of the php file variable names and values gets stored in the session.


Example of PHP List All Session Variables

session1.php
<?php

    session_start();
    $roll
=1;
    $name
="jack";
    $subject
="computer science";
    session_register($roll);
    session_register($name);
    session_register($subject);
?>

session2.php
<?php
    session_start();
    foreach ($_SESSION as $key=>$val)
    echo $key." ".$val;
?>

first run session1.php
then run session2.php

Output

1 jack computer science

Ads