php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14978 session doesn't work
Submitted: 2002-01-10 15:49 UTC Modified: 2002-01-10 15:53 UTC
From: mchin at apollodisplays dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.0.5 OS: Unix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mchin at apollodisplays dot com
New email:
PHP Version: OS:

 

 [2002-01-10 15:49 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-10 15:53 UTC] mfischer@php.net
Please ask support questions at php-general@lists.php.net

 [2004-03-26 11:11 UTC] basurto at canada dot com
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 20:01:29 2024 UTC