how do I fix this " Warning: session_start(): Cannot send session cache limiter"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence k

    how do I fix this " Warning: session_start(): Cannot send session cache limiter"

    How can I find out where my script is outputting to the screen for the
    first time?

    My error logs are full of stuff like this:


    [24-May-2006 19:51:22] PHP Warning: session_start() : Cannot send
    session cache limiter - headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
    on line 14
    [24-May-2006 19:51:22] PHP Warning: Cannot modify header information -
    headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
    on line 26
    [24-May-2006 19:51:26] PHP Warning: session_start() : Cannot send
    session cache limiter - headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
    on line 14
    [24-May-2006 19:51:26] PHP Warning: Cannot modify header information -
    headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
    on line 26
    [24-May-2006 19:54:42] PHP Warning: session_start() : Cannot send
    session cache limiter - headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
    on line 14
    [24-May-2006 19:54:42] PHP Warning: Cannot modify header information -
    headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
    on line 26
    [24-May-2006 19:54:45] PHP Warning: session_start() : Cannot send
    session cache limiter - headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
    on line 14
    [24-May-2006 19:54:46] PHP Warning: Cannot modify header information -
    headers already sent in
    /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
    on line 26



    but the lines they are pointing to are

    session_start() ;
    session_registe r();

  • NC

    #2
    Re: how do I fix this " Warning: session_start() : Cannot send session cache limiter"

    lawrence k wrote:[color=blue]
    >
    > How can I find out where my script is outputting to the screen
    > for the first time?[/color]

    It may not be your script; it could be one of the files you are
    including...
    [color=blue]
    > My error logs are full of stuff like this:[/color]
    ....[color=blue]
    > but the lines they are pointing to are
    >
    > session_start() ;
    > session_registe r();[/color]

    You probably have a blank space or an empty line somewhere between the
    beginning of a file and the first "<?"... Find it and delete it.
    Alternatively, use output buffering; start buffering at the beginning
    of the script and dump the buffer after you're done working with
    sessions...

    Cheers,
    NC

    Comment

    • Guest's Avatar

      #3
      Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;

      In article <1148576336.021 761.302720@38g2 000cwa.googlegr oups.com>,
      lawrence k <lkrubner@geoci ties.com> wrote:
      [color=blue]
      >[24-May-2006 19:51:22] PHP Warning: Cannot modify header information -
      >headers already sent in[/color]

      You're sending some of the body before the session is started. Don't
      do that ;)

      --
      PHP User Discussion Archive Thread Index

      Comment

      • Someuser

        #4
        Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;

        Actually there could be a space or blank line before any <?, after any ?>,
        any html in files included in the script or even a header statement prior to
        the session start statement. You can try starting the session at the
        begining of the file and then moving it back to where you had it until you
        find the offending code.

        Just remember the session start has to be done prior to any output being
        sent.

        James


        Comment

        • tripmonster@gmail.com

          #5
          Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;

          you must place the header() function ontop of everything in the code.
          if your trying to redirect use javascript.

          Comment

          • lawrence k

            #6
            Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;


            Someuser wrote:[color=blue]
            > Actually there could be a space or blank line before any <?, after any ?>,
            > any html in files included in the script or even a header statement prior to
            > the session start statement. You can try starting the session at the
            > begining of the file and then moving it back to where you had it until you
            > find the offending code.
            > Just remember the session start has to be done prior to any output being
            > sent.[/color]

            I know that. My question was how do I find out where the output
            starts? My system has 1800 PHP files. I can't go through them one at a
            time looking for white space..

            Comment

            • lawrence k

              #7
              Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;


              NC wrote:[color=blue]
              > lawrence k wrote:[color=green]
              > >
              > > How can I find out where my script is outputting to the screen
              > > for the first time?[/color]
              >
              > It may not be your script; it could be one of the files you are
              > including...
              >[color=green]
              > > My error logs are full of stuff like this:[/color]
              > ...[color=green]
              > > but the lines they are pointing to are
              > >
              > > session_start() ;
              > > session_registe r();[/color]
              >
              > You probably have a blank space or an empty line somewhere between the
              > beginning of a file and the first "<?"... Find it and delete it.[/color]

              I know that. My question was how do I find out where the output
              starts? Is there an IDE that would check this for me?

              My system has 1800 PHP files. I can't go through them one at a time
              looking for white space.



              [color=blue]
              > Alternatively, use output buffering; start buffering at the beginning
              > of the script and dump the buffer after you're done working with
              > sessions...[/color]

              That would disguise the problem, but a year frow now it would probably
              come back and bite me. I need to fix the true problem, not hide it.

              Comment

              • Rik

                #8
                Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;

                lawrence k wrote:[color=blue]
                > My system has 1800 PHP files. I can't go through them one at a time
                > looking for white space.[/color]


                900
                450
                225
                123
                62
                31
                16
                8
                4
                2
                1

                That's the road to take when searching for this, 11 easy steps, unless the
                problem is in more then one document. Also, a real editor could search files
                for input before '<?'.

                You could offcourse make PHP do the work for you:
                $files = array of files included/'on your system'
                Loop through the text equivalent of your files with a regular expression
                like (.+)<? on the beginning of every file.

                Or use ob_start()
                And 1800 if(ob_get_conte nts()!='') echo "problem is
                before".__FILE_ _','__LINE__;'s

                And it's not a matter of "your system", it's a matter of files that are
                included before the header call().
                If that's indeed > 1800 files:
                - I'm very curious on what bases you put code in different files, and what
                the exact goal of your script actually is to include that many.
                - I'd suggest a more sensible grouping then "1800 files", so you can exclude
                groups (maybe fake output) of files in this kind of troubleshooting .

                Grtz,
                --
                Rik Wasmus


                Comment

                • lawrence k

                  #9
                  Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;


                  Rik wrote:[color=blue]
                  > lawrence k wrote:[color=green]
                  > > My system has 1800 PHP files. I can't go through them one at a time
                  > > looking for white space.[/color]
                  >
                  >
                  > a real editor could search files
                  > for input before '<?'.[/color]

                  Good point. Homesite could do that for me, or Jedit. I appeciate the
                  suggeston.



                  [color=blue]
                  > Or use ob_start()
                  > And 1800 if(ob_get_conte nts()!='') echo "problem is
                  > before".__FILE_ _','__LINE__;'s[/color]

                  Thanks, that is a great idea. I'll try to rig up a test.


                  [color=blue]
                  > - I'm very curious on what bases you put code in different files, and what
                  > the exact goal of your script actually is to include that many.
                  > - I'd suggest a more sensible grouping then "1800 files", so you can exclude
                  > groups (maybe fake output) of files in this kind of troubleshooting .[/color]

                  Every function and class is in its own file, because usually less than
                  300 are needed for any given project, so there is no point including
                  them all on every page. There is a central object that includes them
                  when they are needed.

                  Comment

                  • lawrence k

                    #10
                    Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;


                    NC wrote:[color=blue]
                    > lawrence k wrote:[color=green]
                    > >
                    > > How can I find out where my script is outputting to the screen
                    > > for the first time?[/color]
                    >
                    > It may not be your script; it could be one of the files you are
                    > including...
                    >[color=green]
                    > > My error logs are full of stuff like this:[/color]
                    > ...[color=green]
                    > > but the lines they are pointing to are
                    > >
                    > > session_start() ;
                    > > session_registe r();[/color]
                    >
                    > You probably have a blank space or an empty line somewhere between the
                    > beginning of a file and the first "<?"... Find it and delete it.
                    > Alternatively, use output buffering; start buffering at the beginning
                    > of the script and dump the buffer after you're done working with
                    > sessions...[/color]

                    Well, I probably do have some open white space in the code. I did a
                    search for it and found at last 6 files that were leaking white space.
                    I fixed those 6 files. Sadly, my error logs are still full of "Warning:
                    session_start() : Cannot send session cache"...

                    I'm going crazy. I can't set sessions because my code is leaking white
                    space. I can't find a way to track down that white space. Surely there
                    is an IDE or test kit that will help me track this down?

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: how do I fix this &quot; Warning: session_start() : Cannot send sessioncache limiter&quot;

                      lawrence k wrote:[color=blue]
                      > NC wrote:
                      >[color=green]
                      >>lawrence k wrote:
                      >>[color=darkred]
                      >>>How can I find out where my script is outputting to the screen
                      >>>for the first time?[/color]
                      >>
                      >>It may not be your script; it could be one of the files you are
                      >>including.. .
                      >>
                      >>[color=darkred]
                      >>>My error logs are full of stuff like this:[/color]
                      >>
                      >>...
                      >>[color=darkred]
                      >>>but the lines they are pointing to are
                      >>>
                      >>> session_start() ;
                      >>> session_registe r();[/color]
                      >>
                      >>You probably have a blank space or an empty line somewhere between the
                      >>beginning of a file and the first "<?"... Find it and delete it.
                      >>Alternatively , use output buffering; start buffering at the beginning
                      >>of the script and dump the buffer after you're done working with
                      >>sessions...[/color]
                      >
                      >
                      > Well, I probably do have some open white space in the code. I did a
                      > search for it and found at last 6 files that were leaking white space.
                      > I fixed those 6 files. Sadly, my error logs are still full of "Warning:
                      > session_start() : Cannot send session cache"...
                      >
                      > I'm going crazy. I can't set sessions because my code is leaking white
                      > space. I can't find a way to track down that white space. Surely there
                      > is an IDE or test kit that will help me track this down?
                      >[/color]

                      First of all, maybe "every function and class has its own file" is a bit
                      overkill. I usually group things together - especially functions. Even if you
                      include some unused functions, so what? And you'll save the time necessary to
                      locate and load dozens of individual files.

                      Also, turn on all errors and display the errors. You'll get a message to the
                      effect "Output was started at line xxx in file yyy", which tells you where the
                      code or whitespace caused the headers to be sent.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • lawrence k

                        #12
                        Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;


                        Jerry Stuckle wrote:[color=blue]
                        > lawrence k wrote:[color=green]
                        > > NC wrote:
                        > >[color=darkred]
                        > >>lawrence k wrote:
                        > >>
                        > >>>How can I find out where my script is outputting to the screen
                        > >>>for the first time?
                        > >>
                        > >>It may not be your script; it could be one of the files you are
                        > >>including.. .
                        > >>
                        > >>
                        > >>>My error logs are full of stuff like this:
                        > >>
                        > >>...
                        > >>
                        > >>>but the lines they are pointing to are
                        > >>>
                        > >>> session_start() ;
                        > >>> session_registe r();
                        > >>
                        > >>You probably have a blank space or an empty line somewhere between the
                        > >>beginning of a file and the first "<?"... Find it and delete it.
                        > >>Alternatively , use output buffering; start buffering at the beginning
                        > >>of the script and dump the buffer after you're done working with
                        > >>sessions...[/color][/color]
                        >
                        >
                        > Also, turn on all errors and display the errors. You'll get a message to the
                        > effect "Output was started at line xxx in file yyy", which tells you where the
                        > code or whitespace caused the headers to be sent.[/color]

                        I'm not sure I know what you mean when you say "turn on all errors". We
                        are talking about my error logs - everything is one by default. The
                        logs capture everything, including every notice, warning, parse error,
                        etc. I don't believe you can even turn that stuff off, in the logs.

                        But as I said earlier in the thread, PHP is giving me bum messages that
                        offer no illumination. My error logs are full this one line, repeated
                        over and over again:


                        [18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
                        headers already sent in
                        /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
                        on line 26
                        [18-Jun-2006 07:56:49] PHP Warning: Cannot modify header information -
                        headers already sent in
                        /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
                        on line 26
                        [18-Jun-2006 12:26:19] PHP Warning: session_start() : Cannot send
                        session cookie - headers already sent in
                        /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
                        on line 14
                        [18-Jun-2006 12:26:19] PHP Warning: session_start() : Cannot send
                        session cache limiter - headers already sent in
                        /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
                        on line 14
                        [18-Jun-2006 12:59:05] PHP Warning: session_start() : Cannot send
                        session cookie - headers already sent in
                        /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
                        on line 14
                        [18-Jun-2006 12:59:05] PHP Warning: session_start() : Cannot send
                        session cache limiter - headers already sent in
                        /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
                        on line 14


                        But this is line 14 and 15 of CommandStartSes sion:

                        session_start() ;
                        session_registe r();



                        and this is line 26 of CommandSetMachi neIdOnVisitorsM achine:

                        $success = setcookie("mach ineId", $machineId, time() + 10000000);


                        Obviously, before these two lines are called, some white space has been
                        sent to the browser. But PHP is not telling me where the problem
                        starts.

                        Tha is why I'm wondering if there is some IDE or test system that would
                        let me track down where the white space starts.

                        Comment

                        • Gordon Burditt

                          #13
                          Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;

                          >> >>> session_start() ;[color=blue][color=green][color=darkred]
                          >> >>> session_registe r();
                          >> >>
                          >> >>You probably have a blank space or an empty line somewhere between the
                          >> >>beginning of a file and the first "<?"... Find it and delete it.[/color][/color][/color]

                          Unfortunately, white space and other body output isn't the only
                          thing that causes headers to be sent. Sending headers (e.g.
                          session_start() ) also causes headers to be sent. If you're going
                          to setcookie(), setcookie() before session_start() and before any
                          output.

                          Also, don't call session_start() before session_start() . Limit:
                          one call per PHP hit.

                          session_registe r() should only be used if register_global s is on,
                          which it shouldn't be, so don't use it. Use $_SESSION.

                          [color=blue]
                          >But as I said earlier in the thread, PHP is giving me bum messages that
                          >offer no illumination.[/color]

                          They are telling you where the problem is. White space is a common,
                          and difficult to find, but not the only cause of headers being sent.
                          [color=blue]
                          >My error logs are full this one line, repeated
                          >over and over again:
                          >
                          >
                          >[18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
                          >headers already sent in
                          >/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
                          >on line 26[/color]

                          setcookie() goes before session_start() .
                          [color=blue]
                          >[18-Jun-2006 07:56:49] PHP Warning: Cannot modify header information -
                          >headers already sent in
                          >/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
                          >on line 26
                          >[18-Jun-2006 12:26:19] PHP Warning: session_start() : Cannot send
                          >session cookie - headers already sent in
                          >/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSes sion.php
                          >on line 14[/color]

                          Don't call session_start() twice.
                          [color=blue]
                          >But this is line 14 and 15 of CommandStartSes sion:
                          >
                          > session_start() ;
                          > session_registe r();
                          >
                          >
                          >
                          >and this is line 26 of CommandSetMachi neIdOnVisitorsM achine:
                          >
                          > $success = setcookie("mach ineId", $machineId, time() + 10000000);[/color]

                          Gordon L. Burditt

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: how do I fix this &quot; Warning: session_start() : Cannot send sessioncache limiter&quot;

                            lawrence k wrote:[color=blue]
                            > Jerry Stuckle wrote:
                            >[color=green]
                            >>Also, turn on all errors and display the errors. You'll get a message to the
                            >>effect "Output was started at line xxx in file yyy", which tells you where the
                            >>code or whitespace caused the headers to be sent.[/color]
                            >
                            >
                            > I'm not sure I know what you mean when you say "turn on all errors". We
                            > are talking about my error logs - everything is one by default. The
                            > logs capture everything, including every notice, warning, parse error,
                            > etc. I don't believe you can even turn that stuff off, in the logs.
                            >[/color]

                            Actually, not everything is on by default. E_NOTICE defaults to off - and often
                            contains a lot of good information. And anything can be turned on or off in
                            your log. It's all in the php.ini file.
                            [color=blue]
                            > But as I said earlier in the thread, PHP is giving me bum messages that
                            > offer no illumination. My error logs are full this one line, repeated
                            > over and over again:
                            >[/color]

                            Not necessarily. Gordon gave you some good info, also. Check out his ideas.


                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • lawrence k

                              #15
                              Re: how do I fix this &quot; Warning: session_start() : Cannot send session cache limiter&quot;


                              Gordon Burditt wrote:[color=blue][color=green][color=darkred]
                              > >> >>> session_start() ;
                              > >> >>> session_registe r();
                              > >> >>
                              > >> >>You probably have a blank space or an empty line somewhere between the
                              > >> >>beginning of a file and the first "<?"... Find it and delete it.[/color][/color]
                              >
                              > Unfortunately, white space and other body output isn't the only
                              > thing that causes headers to be sent. Sending headers (e.g.
                              > session_start() ) also causes headers to be sent. If you're going
                              > to setcookie(), setcookie() before session_start() and before any
                              > output.
                              >
                              > Also, don't call session_start() before session_start() . Limit:
                              > one call per PHP hit.[/color]

                              Thank you. Your advice is some of the most helpful that I've gotten.
                              But when I use my text editor to run a global search on all of my code,
                              I only find one call to session_start() .


                              [color=blue]
                              > session_registe r() should only be used if register_global s is on,
                              > which it shouldn't be, so don't use it. Use $_SESSION.[/color]

                              I've deleted the call to session_registe r(). I hope this helps.







                              [color=blue][color=green]
                              > >My error logs are full this one line, repeated
                              > >over and over again:
                              > >
                              > >
                              > >[18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
                              > >headers already sent in
                              > >/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachi neIdOnVisitorsM achine.php
                              > >on line 26[/color]
                              >
                              > setcookie() goes before session_start() .[/color]

                              Oh! That is very good to know. Can I ask where you found that
                              information? This page:



                              says "If a user uses ob_gzhandler or like with ob_start(), the order of
                              output handler is important for proper output. For example, user must
                              register ob_gzhandler before session start."

                              but from that it's not transparent to me that cookies must be called
                              before session_start() . Where is this stated as a general principle?

                              However, I'll now call setcookie before I call session_start() . Hope
                              that helps.

                              Thanks much for all your help

                              Comment

                              Working...