Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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

Report this thread to moderator Post Follow-up to this message
Old Post
Jean Vaillancourt
07-31-04 01:55 AM


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

Report this thread to moderator Post Follow-up to this message
Old Post
Sebastian Lauwers
07-31-04 08:55 AM


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...
75.html
Visit Topic URL to contact author (reg. req'd).  Report abuse: http://www.dbForumz
.com/eform.php?p=451439

Report this thread to moderator Post Follow-up to this message
Old Post
steve
07-31-04 08:55 AM


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...
75.html
Visit Topic URL to contact author (reg. req'd).  Report abuse: http://www.dbForumz
.com/eform.php?p=451440

Report this thread to moderator Post Follow-up to this message
Old Post
steve
07-31-04 08:55 AM


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: 
>
> Bonsoir, (:p)
>
> [...]
> 
>
> This is just because you start the sessions after something has been
> sent to the (client's) browser.
>
> [...]
> 
>
> I wish i could do more.
> 
>
> HTH,
> Sebastian


Report this thread to moderator Post Follow-up to this message
Old Post
Jean Vaillancourt
07-31-04 08:55 AM


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_:
> 
> sent (output 
> line 11 
> been 

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...
75.html
Visit Topic URL to contact author (reg. req'd).  Report abuse: http://www.dbForumz
.com/eform.php?p=451492

Report this thread to moderator Post Follow-up to this message
Old Post
steve
07-31-04 08:55 AM


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: 
> my 
> property 
> of 
> the 
>
> 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).


Report this thread to moderator Post Follow-up to this message
Old Post
Jean Vaillancourt
07-31-04 08:55 PM


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_:
> 
> the 
> beginning of 
> back: 
> a 
> produit 
> session 
> already sent 
> line 11 
> 160 is 
>
> 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...
75.html
Visit Topic URL to contact author (reg. req'd).  Report abuse: http://www.dbForumz
.com/eform.php?p=451804

Report this thread to moderator Post Follow-up to this message
Old Post
steve
08-01-04 01:55 AM


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.

Report this thread to moderator Post Follow-up to this message
Old Post
Colin McKinnon
08-01-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.