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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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 |
|
|||
|
"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 |
|
|||
|
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 |
|
|||
|
"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 |
|
|||
|
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). |
|
|||
|
"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 |
|
|||
|
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. |