note 37727 added to function.serialize

From: Date: Mon, 24 Nov 2003 19:20:46 +0000
Subject: note 37727 added to function.serialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-60918@lists.php.net to get a copy of this message
While writing shopping cart applications i needed a way to keep track of many variables beteween page loads.. i was using a cookie for each but this became hard to manage so I cam up with this simple session object. It serializes the object, base 64 encodes it and sets a cookie for it.. vice versa on page load where it detects the cookie add whatever variables you need to this class btw if you like it, hate it or have any comments send me an email to let me know class session { var $cartID; var $userID; var $userAuth; function session () { //Attempt to load previous session from user cookie //First see if the session was passed through the URL //This is useful to pass stuff between different URL if ($_GET['session']) { $this = unserialize (base64_decode ($_GET['session'])); //Check for the cookie, if none a blank session is created } else { if ($_COOKIE['session']) { $this = unserialize (base64_decode ($_COOKIE['session'])); } } } function save () { setcookie ('session', base64_encode (serialize ($this))); } function delete () { setcookie ('session'); unset ($this); } } ---- Manual Page -- http://www.php.net/manual/en/function.serialize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37727 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37727&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37727&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60918) next »