Using __Sleep() And __Wakeup() For Objects

<?php
     class UserClass {
          public $sessionID;
          public $username;          public function __sleep() {
               session_destroy();
               return array("username");
          }
          public function __wakeup() {
               session_start();
               $this->sessionId = session_id();
          }
     }
     session_start();
     $user = new UserClass;
     $user->sessionId = session_id();
     $seralized_user = serialize($user);     unset($user);
     $user = unserialize($serialized_user);
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.