Results 1 to 4 of 4

Thread: Session - headers Error

  1. #1
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default Session - headers Error

    Hi,

    I don't know how to deal with this error:
    PHP Code:
    Warningsession_start() [function.session-start]: Cannot send session cache limiter headers already sent (output started at XXX.php:15in XXX.php on line 4 
    my php source code:
    PHP Code:
    <?php

    function username($num){
      
    session_start();
      
    $_SESSION['username']=$num;
    }

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>my trial page</title>
    </head>
    <body>
    <?php include ("sidebar.inc"?>
    bla bla
    <?php
    username
    (3);
    ?>
    </body>
    </html>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    http://us3.php.net/ob_start
    I hope that helps you.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    d-machine (09-22-2008)

  4. #3
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    I just do this for every file:

    Code:
    <?php session_start(); ?>
    
    <?php
    
    // Other code here
    
    ?>
    If I put it on the top line like that by itself before anything else it seems to work perfectly. I am not sure if this is good or bad coding practice though, as I am still new to PHP. Hope this helped.

  5. The Following User Says Thank You to Moshambi For This Useful Post:

    d-machine (09-22-2008)

  6. #4
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    Thank you both very much !!

    Now it is working great !

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •