Re: Handling objects as session vars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marcos,

A suggestion to your code changes.

<?phphpinclude("class/object_def.phphp;
session_start();

// First check the $_SESSION for a previous instance of your object 
if (!isisset_SESSION['session_object']))
{
   $_SESSION['session_object'] = new TNTNewClasscod,$password);
}
?>

Try this first. Note I removed the 'if' statement where you were checking for a valid object
instance. I suggest using the PHPHPunction 'is_a' and/or 'is_object'.

Start with this...



David,

This is not a correct statement "sessions work by using cookies, and cookies can't take
phphpbjects".

In PHPHPhe session information is not pushed to the user's browser in a cookie. Only a reference
to the session is stored in a cookie on the user's side. The actual content of the session is
written to a file on the server. 


--- David Collard <memeizawotmeizmgmailom> wrote:

> Marcos R. CaCardosorote:
> 
> i'i'dry using serialize() to turn the object into a string which can 
> then be put in the session, and then ununserialize when you want it back 
> out again
> 
> sessions work by using cookies, and cookies can't take phphpbjects
> 
> ;)
> 
> > I'm trying to use an object as a session var so I could handle its 
> > properties and methods as long as the session is still on. But when I 
> > use a second PHPHPcript the values inside this object are lost. I have 
> > a script like this.
> >
> > <?
> > include("class/object_def.phphp;
> > session_start();
> > $new_object = new TNTNewClasscod,$password);
> > if ($new_object->gegetCod == 0) {
> >  echo $new_object->gegetMsgError;
> > } else {
> >  $_SESSION['session_object'] = $new_object;
> > ?>
> > <script language="JaJavaScript
> >  location.replace("new_script.phphp;
> > </script>
> > <?
> > }
> > ?>
> >
> > then in the script "new_script.phphpI have the following instructions:
> >
> > <?
> > include("class/object_def.phphp;
> > session_start();
> > if ($_SESSION['session_object'] == "") {
> >  echo "there is no session open<brbr;
> >  exit;
> > }
> > echo $_SESSION['session_object']->gegetCod."<brbr;
> > echo $_SESSION['session_object']->gegetName."<brbr;
> > ?>
> >
> > The result from the script new_script.phphplways return empty where 
> > the methods should return something. I've already read the 
> > documentation at wwwwwhphpet, tried what it's shown there and checked 
> > some other sites as well, bu I haven't found a solution yet.
> >
> > Environment:
> >
> > Windows 2003 Server
> > Apache 2.0.54
> > PHPHP.4.0
> > Sun Chili!Soft ASP 3.6.2
> > MyMySQL.0.20a
> > Oracle 9i (through a Oracle 8i NeNetClient
> >
> >
> > TIA,
> > Marcos R. CaCardoso> > BlBlumenau> > Brazil
> >
> 
> -- 
> PHPHPindows Mailing List (hthttp/wwwwwhphpet/)
> To ununsubscribevisit: hthttp/wwwwwhphpet/ununsubhphp> 
> 

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux