Re: sessions and passing variables

From: Date: Mon, 08 Apr 2002 13:10:51 +0000
Subject: Re: sessions and passing variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-92032@lists.php.net to get a copy of this message
sure. if all users should have access to this instance of your object, then you could store the serialized object in a file, everyone has access to and unserialize it if needed.But don't forget to include your object-surcecode before unserializing the object, or you'll lose your methods. If users should also have write access to the object, you also have to make sure, that only one user can access the file for writing at one time, or your data gets probably screwed. The easiest way would be storing the object not in a file but in a database, so you don't have to care about locking. But do you really need the same instance of the object? why not simply perform a $obj =& new Class(); ---------------------------------------------------------------------------- ---------- Code for Storing: <?php $strData = serialize($data); $fp = fopen("globalObjectData.inc", "w"); fwrite($fp, $strData); fclose($fp); ?> Code for accessing: <?php // include object source before unserializing include "myObjectSrc.php"; $fp = fopen("globalObjectData.inc", "w"); $strData = fread($fp, filesize("globalObjectData.inc")); fclose($fp); // so we have our object back $obj = unserialize($strData); ---------------------------------------------------------------------------- "Rarmin" <rarmin@yahoo.com> schrieb im Newsbeitrag news:3CB15A28.1050401@yahoo.com... > Is there a way to pass variables (objects) across the different > sessions. I thought of sharing one object for all users that access my > web site (it's an object that does some operations with files common to > all users, like reading and writing). Any ideas? > > Tnx in advance. > Armin >

« previous php.general (#92032) next »