Problem with object in $_SESSION and include

This is a discussion on Problem with object in $_SESSION and include within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I have to put an object in $_SESSION and to use it later in the session. My class is ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-30-2004
Jean Vaillancourt
 
Posts: n/a
Default Problem with object in $_SESSION and include

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
Reply With Quote
  #2 (permalink)  
Old 07-31-2004
Sebastian Lauwers
 
Posts: n/a
Default Re: Problem with object in $_SESSION and include

Jean Vaillancourt wrote:
> Hi,


Bonsoir, (:p)

[...]

> Warning: Cannot send session cache limiter - headers already sent (output
> started at [...]/Produit.php:160) in [...]/ctrlappl.php on line 11


This is just because you start the sessions after something has been
sent to the (client's) browser.

[...]

> Can someone help?


I wish i could do more.

> Jean Vaillancourt, Mascouche


HTH,
Sebastian
Reply With Quote
  #3 (permalink)  
Old 07-31-2004
steve
 
Posts: n/a
Default Re: Problem with object in $_SESSION and include

"Jean Vaillancourt" wrote:
> 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().

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Problem-...ict135175.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451439
Reply With Quote
  #4 (permalink)  
Old 07-31-2004
steve
 
Posts: n/a
Default Re: Re: Problem with object in $_SESSION and include

"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).

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Problem-...ict135175.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451440
Reply With Quote
  #5 (permalink)  
Old 07-31-2004
Jean Vaillancourt
 
Posts: n/a
Default Re: Problem with object in $_SESSION and include

But I changed my object to one with absolutely no instruction.
It just had an empty constructor and no method and no variable.
And I still got the error. I don't think it's an echo problem.

Jean

Le Sat, 31 Jul 2004 03:07:09 +0200, Sebastian Lauwers a écrit*:

> Jean Vaillancourt wrote:
>> Hi,

>
> Bonsoir, (:p)
>
> [...]
>
>> Warning: Cannot send session cache limiter - headers already sent (output
>> started at [...]/Produit.php:160) in [...]/ctrlappl.php on line 11

>
> This is just because you start the sessions after something has been
> sent to the (client's) browser.
>
> [...]
>
>> Can someone help?

>
> I wish i could do more.
>
>> Jean Vaillancourt, Mascouche

>
> HTH,
> Sebastian


Reply With Quote
  #6 (permalink)  
Old 07-31-2004
steve
 
Posts: n/a
Default Re: Re: Problem with object in $_SESSION and include

"Jean Vaillancourt" wrote:
> But I changed my object to one with absolutely no instruction.
> It just had an empty constructor and no method and no variable.
> And I still got the error. I don’t think it’s an echo
> problem.
>
> Jean
>
> Le Sat, 31 Jul 2004 03:07:09 +0200, Sebastian Lauwers a écrit*:
>
> > Jean Vaillancourt wrote:
> >> Hi,

> >
> > Bonsoir, (:p)
> >
> > [...]
> >
> >> Warning: Cannot send session cache limiter - headers already

> sent (output
> >> started at [...]/Produit.php:160) in [...]/ctrlappl.php on

> line 11
> >
> > This is just because you start the sessions after something has

> been
> > sent to the (client’s) browser.
> >
> > [...]
> >
> >> Can someone help?

> >
> > I wish i could do more.
> >
> >> Jean Vaillancourt, Mascouche

> >
> > HTH,
> > Sebastian</font>


But you did state "Warning: Cannot send session cache limiter -
headers already sent ", this means something was output already, even
html headers. This will 99% fixed if you cache using ob_start, give
it a try (one instruction, ez to do).

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Problem-...ict135175.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451492
Reply With Quote
  #7 (permalink)  
Old 07-31-2004
Jean Vaillancourt
 
Posts: n/a
Default 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).


Reply With Quote
  #8 (permalink)  
Old 07-31-2004
steve
 
Posts: n/a
Default Re: Re: Re: Problem with object in $_SESSION and include

"Jean Vaillancourt" wrote:
> 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().

>
> 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).</font>[/quote:5749aa770e]


No, I think you are echo’ing http header info. It is easy to test
(specially if you have a debugger). You can echo out the content of
ob_get_content() periodically (since you did ob_start), and it would
show you what is in the cache.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Problem-...ict135175.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451804
Reply With Quote
  #9 (permalink)  
Old 08-01-2004
Colin McKinnon
 
Posts: n/a
Default Re: Problem with object in $_SESSION and include

Jean Vaillancourt spilled the following:


> 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.
>


Trailing whitespace/non-printable chars in the include file? Try referencing
the session before including the class definition e.g.

session_register('some_random_name');
require_once('Produit.php');
$x=&$_SESSION['produit'];

HTH

C.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0