Home Tutorial Php List PHP list all session variables

 
 

PHP list all session variables
Posted on: October 31, 2009 at 12:00 AM
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

Related Tags for PHP list all session variables:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.