473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

session variables?

can session variable hold objects that can later be reference by other
pages? if so, i get an "incomplete object" error when i try to call
methods from the object I have stored in the session. any help is
appreciated.

donnie

Jul 17 '05 #1
6 3877
Donnie <dq******@REMOVE-THISyahoo.com> wrote in message news:<AQ***************@fe61.usenetserver.com>...
can session variable hold objects that can later be reference by other
pages? if so, i get an "incomplete object" error when i try to call
methods from the object I have stored in the session. any help is
appreciated.


Did you read the manual <http://in2.php.net/session> ?

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
R. Rajesh Jeba Anbiah wrote:
Donnie <dq******@REMOVE-THISyahoo.com> wrote in message news:<AQ***************@fe61.usenetserver.com>...
can session variable hold objects that can later be reference by other
pages? if so, i get an "incomplete object" error when i try to call
methods from the object I have stored in the session. any help is
appreciated.

Did you read the manual <http://in2.php.net/session> ?


Yes, but I am not sure it answered my question. Perhaps I don't
understand it.

Jul 17 '05 #3
Donnie wrote:
R. Rajesh Jeba Anbiah wrote:
Donnie <dq******@REMOVE-THISyahoo.com> wrote in message news:<AQ***************@fe61.usenetserver.com>...
can session variable hold objects that can later be reference by other
pages? if so, i get an "incomplete object" error when i try to call
methods from the object I have stored in the session. any help is
appreciated.

Did you read the manual <http://in2.php.net/session> ?


Yes, but I am not sure it answered my question. Perhaps I don't
understand it.


You have to have the class defined before using objects of that class.
<?php //page1
class foo {
function bar() {echo "foobar";}
}

session_start();
$x = new foobar;
$x->print_me();
$_SESSION['foo'] = $x;
?>
<?php //page2 (with error)
session_start();
$y = $_SESSION['foo'];
$y->bar(); // incomplete object
?>
<?php //page3
class foo {
function bar() {echo "foobar";}
}

session_start();
$z = $_SESSION['foo'];
$z->print_me();
?>

The best thing to do is to include the class definition in a file for
itself and require that file whenever that class is needed.

<?php //foo.class.php
class foo {
function bar() {echo "foobar";}
}
?>

<?php
require_once 'foo.class.php';
session_start();
$w = $_SESSION['foo'];
$w->bar();
?>

--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #4
Pedro Graca wrote:
<?php
require_once 'foo.class.php';
session_start();
$w = $_SESSION['foo'];
$w->bar();
?>


I'm having the same trouble. When I try that, I get the following:

Warning: session_start() [function.session-start]: Cannot send session cache
limiter - headers already sent (output started
at /srv/www/htdocs/.../test_class.inc:16) in /srv/www/htdocs/.../test2.php
on line 4

Where test_class.inc has a simple class definition.
test1.php creates an instance of the class and stores it as
$_SESSION['junk'].
And test2.php looks like:
<?php

require_once ('test_class.inc');
session_start();

$_SESSION['junk']->display();

?>

It seems to process everything well enough, but the warning is annoying. Is
this a problem? I'm sure it's just a matter of turning an option off
somewhere to get rid of the warning, but should it not work without getting
it in the first place?

php 4.3.1
apache 1.3.27
linux kernel 2.4.20

John
Jul 17 '05 #5
John R Schleigh IV wrote:
<snip>
Warning: session_start() [function.session-start]: Cannot send session cache
limiter - headers already sent (output started ^^^^^^^^^^^^^^ at /srv/www/htdocs/.../test_class.inc:16) in /srv/www/htdocs/.../test2.php ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Line 16 of 'test_class.inc' is the first output to the browser your
script does. As it is executed /before/ the session_start() you get that
error.
on line 4
<snip>
And test2.php looks like:
<?php

require_once ('test_class.inc');
session_start();
It /may/ be enough to switch the order of these two lines.

Anyway, the class definition shouldn't output anything at all to the
browser. Only a class instance, when it calls the class methods, should
do that.
$_SESSION['junk']->display();

?>

It seems to process everything well enough, but the warning is annoying. Is
this a problem?
I believe it should be classified as an error, not a warning.
I think your pages won't work if they're based on cookies after that
warning.
I'm sure it's just a matter of turning an option off
somewhere to get rid of the warning, but should it not work without getting
it in the first place?


It's definitely better to remove the warning than to turn one option off
and keep it hidden.
If switching the require() and the session_start() does not work, you
have to rethink your test_class.inc -- maybe you'd even prefer not to
try the switch before dealing with test_class.inc.
Happy Coding :)

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #6
Pedro Graca wrote:
Anyway, the class definition shouldn't output anything at all to the
browser. Only a class instance, when it calls the class methods, should
do that.


Here is the class definition file, I could not see that it sends anything to
the browser. When I place the class definition before the session_start()
it works fine, no error. But when I include the class definition, it still
spits out that error message.

<?php

/*
* test_class.inc
*/

class test{

var $test;

function display(){
echo "<pre>\n";
print_r ($this->test);
echo "</pre>\n";
}
}

?>

When I remove the closing "?>" from test_class.inc, everything worked fine.
No errors. I then put the "?>" back in and was very particular to make
sure there were no trailing lines or whitespace. It still worked. Perhaps
I had an extra line after the "?>"? I could see how that might send
something to the browser. Thanks for the help!

--
John
___________________
I can read your mind, and you should be ashamed of yourself.

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
4
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
31
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
3
by: Phillip N Rounds | last post by:
I'm writing a user control which has two states: Active & InActive. I additionally am required that there to be only one active control per page, and all logic has to be contained within the...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
26
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
12
by: MrHelpMe | last post by:
Hello again all, I've finished my whole application and now I don't like the whole session variables that I am using. I have a form, user fills in info clicks submit and using CDOSYSMail an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.