RE: [PHP] problems with sessions.
| From: | Jeroen Wesbeek | Date: | Wed, 01 Nov 2000 10:30:23 +0000 |
| Subject: | RE: [PHP] problems with sessions. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-23135@lists.php.net to get a copy of this message | ||
Hi Deepak,
Sessions (mainly) use cookies to transmit session id's back and forth
the client. Cookies however are stored in the HTML headers.
This means that you can only use a start_session (the cookie
is placed at the client) before you output any script output
(and thus HTML headers).
What you are doing is first generating output (html, title,
etcetera) and then calling the start_session which won't
work since the cookie information cannot be put in the HTML
headers because you have already sent HTML headers.
Try this:
-----------session.php-------------
<?php
session_start();
if (!session_is_registered('count')) {
session_register('count');
}
$count++;
?>
<html>
You visited <?php print $count; ?> times. <p>
</html>
---------------end----------------
Grtz,
dowebwedo
Jeroen Wesbeek
.programming
St. Jacobsstraat 16
Postbus 448 | 3500 AK Utrecht
The Netherlands
p 030 2348110 | f 030 2348605
[roses are red, violets are blue,
I am schizophrenic and so am I ]
-----Original Message-----
From: Deepak Chawla [mailto:dchawla@usa.unl.edu]
Sent: woensdag 1 november 2000 10:05
To: php-general@lists.php.net
Subject: [PHP] problems with sessions.
I recently started working with sessions... and have already started
running into problems. Someone please help me out...
I have two (almost identical) .php files. I have the --enable-trans-sid
set.
----------------session01.php------------------------
<html>
<head> <title> Session 01 </title>
</head>
<body>
<p> This is the first file in session. The variable is
<?
session_start();
session_register("count");
print("$count");
$count++;
?>
</p>
<p> Now go to <a href="session02.php"> Click here </a> </p>
</body>
</html>
-----------------------------------------------------------------
----------------------session02.php-----------------------------
<html>
<head>
</head>
<body>
<p> This is the second file in session. The variable is
<?
session_start();
session_register("count");
print("$count");
$count++;
?>
</p>
<p> Now go back <a href="session01.php"> Click here </a> </p>
</body>
</html>
------------------------------------------------------------
Although the scripts are working, they are also producing some error
messages. I can't figure out why so. Can someone help me ?
----------------error messages-----------------------
This is the first file in session. The variable is
Warning: Cannot send session cookie - headers already sent by (output
started at /home/dchawla/public_html/Learning/session01.php:6) in
/home/dchawla/public_html/Learning/session01.php on line 7
Warning: Cannot send session cache limiter - headers already sent (output
started at /home/dchawla/public_html/Learning/session01.php:6) in
/home/dchawla/public_html/Learning/session01.php on line 7
0
Now go to Click here
---------------------------------------------------------------------
I even tried removing the session_start(); functions
(session_register(...); implicitly starts the session). But that didn't
help either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net