Re: Re: Problem with object in $_SESSION and include
Well, it worked with serialize - unserialize.
I also put ob_start() - od_end_clean() around session_start()
and I got no warning. It was ok when I wrote @session_start() too.
I just don't understand why I got a warning (Cannot send session
cache limiter - headers already sent) with a completely empty
object. Does PHP echo something when you declare an object?
Anyway, I thank everyone for your help.
Jean
Le Fri, 30 Jul 2004 22:03:36 -0400, steve a écrit*:
> "steve" wrote:
> > [quote:4e18fefa32="Jean Vaillancourt"]Hi,
> >
> > I have to put an object in $_SESSION and to use it later in the
> > session.
> >
> > My class is defined in a file which I include at the beginning of
> my
> > program,
> > just after my session has been started:
> >
> > session_start();
> > require_once "include/Produit.php";
> >
> > When my program comes back, I try to get my stored object back:
> >
> >
> > line 3: $x = new Produit();
> > line 4: $x=&$_SESSION[’produit’];
> > line 5: echo "*** produit:".$x -> nomFR;
> >
> > and I get this error:
> >
> > Fatal error: The script tried to execute a method or access a
> property
> > of an
> > incomplete object. Please ensure that the class definition produit
> of
> > the
> > object you are trying to operate on was loaded _before_ the session
> > was
> > started in /[...]/maj.php on line 5
> >
> > I then invert my session_start and the include:
> >
> > line 10: require_once "include/Produit.php";
> > line 11: session_start();
> >
> > and I get this warning:
> >
> > Warning: Cannot send session cache limiter - headers already sent
> > (output
> > started at [...]/Produit.php:160) in [...]/ctrlappl.php on line 11
> >
> > where /Produit.php is the file containing my class and line 160 is
> the
> > very
> > last line of the file.
> >
> > Can someone help?
> >
> > Jean Vaillancourt, Mascouche
>
> To save an object to session, use serialize() and
> unserialize().[/quote:4e18fefa32]
>
> I believe the 2nd problem of yours relates to something being echoed
> before session_start. Use something like ob_start() to cache content
> (see manual).
|