Storing Complex Data Types in Sessions : Session Variables « Cookie Session « PHP






Storing Complex Data Types in Sessions

 
<?php
  session_start();
  
  class myclass {
    protected $myvalue;
    
    public function setmyvalue ($newvalue){
      $this->myvalue = $newvalue;
    }
    
    public function getmyvalue (){
      return $this->myvalue;
    }
  }
  
  $_SESSION['myclass_value'] = new myclass ();
  
  function outputsessions (){
    $_SESSION['myclass_value']->setmyvalue ("Hello World");
    echo $_SESSION['myclass_value']->getmyvalue ();
  }
  outputsessions();
?>
  
  








Related examples in the same category

1.A session variable can be destroyed with a call to session_unregister().
2.Accessing Session Variables
3.Adding Session Data
4.Checking Session Data
5.Reading Session Data
6.Registering Variables with a Session
7.Registering an Array Variable with a Session
8.Storing Complex Data Types to session
9.Storing Simple Data Types in Sessions