#14978 [Com]: session doesn't work

From: Date: Fri, 26 Mar 2004 16:11:11 +0000
Subject: #14978 [Com]: session doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56888@lists.php.net to get a copy of this message
ID: 14978 Comment by: basurto at canada dot com Reported By: mchin at apollodisplays dot com Status: Bogus Bug Type: Session related Operating System: Unix PHP Version: 4.0.5 New Comment: baZz at basurto @ canada dot com ============================================================ Hi, I was having the same problem on php 4.0.3, but it is easy to solve. (At least this work for me). First of all let me tell you that this warning is sent because you are trying to start a session that already start. SOLUTION ============================================================ The warning that php sends to you is the following: Warning: Cannot send session cookie - headers already sent by (output started at /home/www.apollodisplays.com/public_html/mainpage.php:10) in /home/www.apollodisplays.com/public_html/mainpage.php on line 29 Warning: Cannot send session cache limiter - headers already sent (output started t /home/www.apollodisplays.com/public_html/mainpage.php:10) in /home/www.apollodisplays.com/public_html/mainpage.php on line 29 The only thing that you have to do is put your session_start(); line within the <head> tags of your html or just before the line 10. Why before the line 10? because the warning tells you that the headers was send in that line. EXAMPLE ============================================================ Here I include a very simple example in order that you test that your php session is working. session_test.php ============================================================ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <?php session_start('mysession'); class Cus{ var $cusid; function newCus($cusid, $index){ $this->cusid[$index] = $cusid; } function getCus(&$tmparray){ for($i = 0; $i < count($this->cusid); $i++){ $tmparray[$i] = $this->cusid[$i]; } } } $customer = new Cus(); $customer->newCus("Cliente 1",0); $_SESSION['customer'] = $customer; echo "<a href=\"./session_test2.php\">Página 2 de la sesión</a><br>"; print_r($_SESSION); ?> </body> </html> session_test2.php ============================================================ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <?php session_start(); class Cus{ var $cusid; function newCus($cusid, $index){ $this->cusid[$index] = $cusid; } function getCus(&$tmparray){ for($i = 0; $i < count($this->cusid); $i++){ $tmparray[$i] = $this->cusid[$i]; } } } $_SESSION['customer']->getCus($tmparr); print_r($tmparr); session_unset(); session_destroy(); ?> </body> </html> I really hope that this help you. Previous Comments: ------------------------------------------------------------------------ [2002-01-10 15:53:16] mfischer@php.net Please ask support questions at php-general@lists.php.net ------------------------------------------------------------------------ [2002-01-10 15:49:45] mchin at apollodisplays dot com i can't use session, give me an error when use ie 6. Warning: Cannot send session cookie - headers already sent by (output started at /home/www.apollodisplays.com/public_html/mainpage.php:10) in /home/www.apollodisplays.com/public_html/mainpage.php on line 29 Warning: Cannot send session cache limiter - headers already sent (output started t /home/www.apollodisplays.com/public_html/mainpage.php:10) in /home/www.apollodisplays.com/public_html/mainpage.php on line 29 my code is very simple. see below ----> session_start(); session_register("userright"); $HTTP_SESSION_VARS["userright"]=$right; anyone have any idea ? thankx ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=14978&edit=1

« previous php.bugs (#56888) next »