Share on Google+Share on Google+

PHP list all session variables

Advertisement
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

Advertisements

Posted on: October 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.