Grow your CSS skills. Land your dream job.

Session_start(); errors, need help ASAP

  • # January 31, 2010 at 4:20 pm

    Right, just recently I’ve started getting error messages at the top of my pages going on about not being able to send headers and whatnot.

    "Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/chobe1/public_html/scotland.php:1) in /home/chobe1/public_html/base.php on line 1"

    They only show up when my client adds text onto the page and I assumed he must of edited something extra by accident but I checked and everything is the same and I can’t work out why it’s happening, I don’t think he wants a massive error message above the majority of his pages.

    All I know that could be causing it is that he is editing it in notepad and I’m editing mine in dreamweaver, normally I wouldn’t point something silly like that but it’s the only difference, if anyone wants to try to help let me know and I’ll link you to the pages. so you can see for your self.

    # January 31, 2010 at 5:35 pm

    Basically this error occurs when you try to output to the browser BEFORE calling the session_start(). It has to be the first line of code on the page.

    I can have a look for you if you have the sample code causing the error

    # January 31, 2010 at 5:43 pm

    Sure hang on but it is at the top of the page, it’s in a <php? include ?> though

    the page the sesion is in is

    Code:
    < ?php session_start();

    $dbhost = "localhost";
    $dbname = "chobe1_stranded";
    $dbuser = "chobe1_admin";
    $dbpass = "workbook";

    mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
    ?>
    < ?php
    $host = 'localhost';
    $username = 'chobe1_admin';
    $password = 'workbook';
    $database = 'chobe1_stranded';
    ?>

    Don’t ask me why it’s like that, my friend did it a while back and I’ve had no problems until the last week.

    and on the pages it shows up on the include is before everything on line 1.

    # January 31, 2010 at 6:50 pm

    Is that file scotland.php? Because that is the file that the error is being flagged on. Everything looks fine to me in that code so it must be another file causing the problem

    # February 1, 2010 at 11:19 am

    Here are all the pages linked to it:

    http://stranded-uk.com/itemLeic1.php
    The actually displayed page:

    Code:
    < ?php include "base.php"; ?>
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



    < ?php include("nav.html"); ?>

    ?Stranded UK: Leicester 5th March?

    STRANDED LEICESTER returns for the LAST time before summer! This is one event you will not want to miss out on!! For the first time ever STRANDED LEICESTER will be meeting with 2 other cities for the wildest bar crawl ever!

    ? Stranded T-shirt

    ? FREE shot in every venue!

    ? Drinks prizes on the coach!

    ? RETURN travel to a mystery city!

    ? FREE entrance into ALL bars and clubs!

    ? Games and goodies throughout the night!

    ? 100’s of students from all over the country in one big super club!

    < ?php

    if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
    {
    ?>

    By clicking the buy now button you are agreeing to are terms and conditions.


    Sizes




    < ?php

    }
    else
    {
    ?>

    Purchases can be made without a Stranded account, however if you do wish to make an account in order to save time for future purchases please click here.

    If you do not wish to make an account and just wish to purchase a shirt please click the button below to continue to checkout.

    < ?php
    }
    ?>

    The base file from earlier:

    Code:
    < ?php session_start();

    $dbhost = "localhost";
    $dbname = "chobe1_stranded";
    $dbuser = "chobe1_admin";
    $dbpass = "workbook";

    mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
    ?>
    < ?php
    $host = 'localhost';
    $username = 'chobe1_admin';
    $password = 'workbook';
    $database = 'chobe1_stranded';
    ?>

    The navagation bar, no php but it’s connected through an include:

    and I believe that’s it, it’s probably something silly I missed because I’m not to strong with php but still.

    # February 1, 2010 at 1:46 pm

    The only thing I can think of is that there is a gap between where the file actually starts and where the code starts e.g. You’ve accidentally hit return before typing the code. This whitespace could cause the error.

    # February 1, 2010 at 2:00 pm

    In which file, I don’t see it.

    # February 1, 2010 at 2:14 pm

    Sorry, I didn’t mean there was, I just meant there could have been.

    The error you are getting basically means that session_start() is not the first line of content outputted to the browser.

    It sounds like this is your problem and solution so give it a go

    http://kasolutions.wordpress.com/2009/0 … eady-sent/

    # February 1, 2010 at 2:22 pm

    So there might be hidden characters? That kind of helps but I have no clue how I would go about removing them.

    # February 1, 2010 at 2:30 pm

    I’m going to assume you are on Windows. So you will need to open the file in a binary editor, namely VIM http://www.vim.org/download.php

    It will either be in the main file or the PHP file that you included and will be on the first line. Just delete the extra characters and save the file. I have not used VIM before though so am not sure how it works

    # February 1, 2010 at 3:12 pm

    Yea, that was the problem, I used Notepad++ and encoded it to UTF-8 without BOM and it did the trick, thank you so much (:

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".