Welcome to dbForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Problem with object in $_SESSION and include

 
   Database Forums (Home) -> PHP RSS
Next:  sample database  
Author Message
Jean Vaillancourt

External


Since: Jul 30, 2004
Posts: 3



(Msg. 1) Posted: Fri Jul 30, 2004 7:52 pm
Post subject: Problem with object in $_SESSION and include
Archived from groups: alt>comp>lang>php (more info?)

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

 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
Sebastian Lauwers2

External


Since: Jul 24, 2004
Posts: 42



(Msg. 2) Posted: Fri Jul 30, 2004 9:53 pm
Post subject: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 3) Posted: Fri Jul 30, 2004 9:57 pm
Post subject: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]

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().
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 4) Posted: Fri Jul 30, 2004 10:00 pm
Post subject: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]

steve wrote:
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().


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).
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
Jean Vaillancourt

External


Since: Jul 30, 2004
Posts: 3



(Msg. 5) Posted: Fri Jul 30, 2004 11:53 pm
Post subject: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 6) Posted: Sat Jul 31, 2004 12:25 am
Post subject: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]

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).
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
Jean Vaillancourt

External


Since: Jul 30, 2004
Posts: 3



(Msg. 7) Posted: Sat Jul 31, 2004 3:28 pm
Post subject: Re: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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).<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 655



(Msg. 8) Posted: Sat Jul 31, 2004 4:26 pm
Post subject: Re: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]

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().[/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).</font>


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.
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
Colin McKinnon

External


Since: Apr 21, 2004
Posts: 38



(Msg. 9) Posted: Sat Jul 31, 2004 7:53 pm
Post subject: Re: Problem with object in $_SESSION and include [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Problem with object in $_SESSION and include 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
include within include, using a relatve path - Hi, I have noticed something in PHP's include mechanism that surprised me. If you include a script that itself contains an include command using a relative path, that path is interpreted from the position of the 'outermost' script, not that of the scrip...

how to add an array to $_SESSION - Hi, Does anyone know how to add an array to $_SESSION? thanks A

a simple clarification about $_SESSION - If I define $_SESSION['x']=5; and later, use $x say, as, $y = $x * $x; will it work only if register_globals is set to On? Am i correct in saying that usage of $x in place of $_SESSION['x'] will not work if register_globals is Off? TIA, Regards,..

$_SESSION on a mobile phone - I have a web application that uses $_SESSION['tt-login']; to see if the session is logged in. Everything works fine when using an internet browser (Firefox, IE, Flock, Safari) but when I try to access the page on my mobile phone (Blackberry Curve) it..

Problem with object cloning in PHP5 - When I clone an istance of System class I want to clone all SubSystem istances in $subsystems array too, so I tryed with this code: class System { public $name; public $subsystems = array(); function __construct($name){ $this->nam...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]