SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Newbie having problem with sessions

    Hi just getting started with PHP

    I've already put some basic code together on my hosting space using PHP and MySQL together and that seems to be working ok.

    I now what to create a login area for administrators but when I upload the script it spits back the following error message

    PHP Code:
    <?php
    session_start
    ();

    // If session variable doesen't exist, register it
    if (!isset($_SESSION['test'])) {
        
    $_SESSION['test'] = 'Hello World!';
        echo 
    '$_SESSION[\'test\'] is registered.<br />' 'Please refresh page';
    } else {
        
    // Itsregistered so display it
        
    echo '$_SESSION[\'test\'] = ' $_SESSION['test'];
    }
    ?>
    you might recognise this little bit of code from a certain PHP book!!??

    but when I test it I get this error

    Warning: Cannot send session cache limiter - headers already sent (output started at /home/danielgold/public_html/php/sessions/3.php:2) in /home/danielgold/public_html/php/sessions/3.php on line 3 $_SESSION['test'] is registered.
    Please refresh page

    my php setting can be view at info.php

    any ideas??

  2. #2
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add ob_start() to the first line of your code and ob_end_flush() to the last one.

  3. #3

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is
    PHP Code:
    <?php
    the first line in /home/danielgold/public_html/php/sessions/3.php? If not, it explains the error. In this case simply remove the previous lines respectively reorder your code as you cant do a session_start() when you have already sent output.


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
  •