Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    173
    Thanks
    5
    Thanked 12 Times in 11 Posts

    Question Warning: session_start() [function.session-start]:.... help? :)

    Hey there

    I'm working on a forum and suddenly, without me changing anything the following error message started to appear on the absolute top of the site. I've read posts on other forums, and searched here, but i can't seem to find a solution. I've looked for white spaces before and after the PHP tag, which some adviced me to remove, but i can't find any. (checked in several editors)
    The error message says that the headers is was already sent by line 1 in header.php, but that's the first line on that page. The header file is included into my index.php file, but i don't have a session_start() there.

    Any ideas what's gone wrong here? I'm loosing hair

    Error message:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\forum_self\header.php:1) in C:\xampp\htdocs\forum_self\header.php on line 1


    Header code:
    PHP Code:
    <?php session_start(); ?>
    <!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>Mitt forum - Nicklas Sandell</title>
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>

    <body>
    <div id="header">
    <h2><a href="index.php">Mitt forum</a></h2>
    <div class="header-right">
    <?php
    if($_SESSION['username'] !== ''){
    $username $_SESSION['username'];

    $connect_host 'localhost';
    $connect_username 'root';
    $connect_password '';
    $connect_db_name "mittforum";
    $connect_tbl_name "users";
                
    mysql_connect("$connect_host""$connect_username""$connect_password") or die(mysql_error());
    mysql_select_db("$connect_db_name") or die(mysql_error());

    $sql mysql_query("SELECT * FROM $connect_tbl_name WHERE username='$username'");
    $row mysql_fetch_array($sql);
    mysql_close();
    }
    ?>
    Välkommen <?php echo $row['name']; ?>

    </div> <!-- header-right -->
    </div>

    <div id="menu">
        <ul>
            <li><a href="index.php">Hem</a></li>
            <li>
            <?php
            
    if($_SESSION['username'] == ''){
                echo 
    '<a href="login.php">Logga in</a>';
                echo 
    '<li><a href="register.php">Registrera ett konto</a></li>';
            }else {            
                echo 
    '<a href="account.php?usr=' $row['id'] . '">Mitt konto</a>';
                echo 
    '<li><a href="logout.php">Logga ut</a></li>';
            }
            
    ?></li>
        </ul>
    </div> <!-- menu -->
    Thanks in advance!


    EDIT: I forgot to say that it still does work just as normal, so i don't understand why the error is showing up? owh!
    Last edited by nikee; 02-04-2010 at 05:38 PM. Reason: Forgot to mention a thing

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,470
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Is the script you show above "included" in another script that also has session_start?
    Try commenting-out the session_start in the script above and see what happens.

    EDIT ....
    I now see I didn't read the first post good enough.
    Put the session_start in your index script instead of the included one.


    .

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    The error message is pretty self explanatory. You've got an error because you've had output in header.php on the first line. Be sure there are no spaces or blank lines before the <?php as even a single carriage return or space/tab is output and will cause this
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    Regular Coder
    Join Date
    Jan 2009
    Posts
    173
    Thanks
    5
    Thanked 12 Times in 11 Posts
    Thanks for the reply mlseim

    As i said in my first post, the header.php file is included to index.php (and other pages), but none of the pages it's included to has the session_start() function included.

    If i comment it out, the error dissapears. But the session function stop working..

  • #5
    Regular Coder
    Join Date
    Jan 2009
    Posts
    173
    Thanks
    5
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by JAY6390 View Post
    The error message is pretty self explanatory. You've got an error because you've had output in header.php on the first line. Be sure there are no spaces or blank lines before the <?php as even a single carriage return or space/tab is output and will cause this

    there's nothing :O Same thing in dreamweaver...



    Now that i re-think, i did change the charset earlier, so that swedish characters is displayed directly. I also opened the header.php file in notepad, and re-saved it in UTF-8 encoding. Can that be why??


    EDIT: I copied all of the content in header.php, made a new textfile, pasted the code and changed it to php file format. Still not working
    Last edited by nikee; 02-04-2010 at 05:51 PM.

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I have heard that the character encoding makes a difference sometimes yeah. There's something called the Byte Order Mark which causes this although I've not played with it and not all that well versed in it. If I remember correctly it was N++ that caused the BOM the last time I saw it. Can you show your code for the index.php up to the include just in case it is that
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Here's a link to the last one I saw, and apparently it IS an encodin issue
    http://forum.phpvideotutorials.com/s...yte+order+mark
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #8
    Regular Coder
    Join Date
    Jan 2009
    Posts
    173
    Thanks
    5
    Thanked 12 Times in 11 Posts
    Aaaaand i fixed it!

    I copied the text, created a new file in DREAMWEAVER, pasted the code and saved it. Woala, runs like a dream now!

    Thanks for the help though, appreciate it!

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,470
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Glad you got it ...
    sometimes hashing stuff around on here triggers some ideas ... creates "aha" moments.


  •  

    Posting Permissions

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