can I still send cookies after I've called session_start()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lkrubner@geocities.com

    can I still send cookies after I've called session_start()

    I was trying to set a cookie before I called session_start() and it was
    giving me an error. But isn't sessions really just a cookie? Why would
    it matter if I sent a cookie before session_start? Can I set them
    afterwards?

  • DJ Craig

    #2
    Re: can I still send cookies after I've called session_start()

    You *can* set a cookie without calling session_start() . Do you mean a
    session variable? You can't do this without calling session_start() :
    $_SESSION['sessionvar'] = 'value';
    But you can do this:
    setcookie('cook iename', 'value', time()+36000);
    and then read the cookie like this:
    $_COOKIE['cookiename'];

    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


    Comment

    • lkrubner@geocities.com

      #3
      Re: can I still send cookies after I've called session_start()

      >You *can* set a cookie without calling session_start() . Do you mean a[color=blue]
      >session variable? You can't do this without calling session_start() :
      >$_SESSION['sessionvar'] = 'value';[/color]

      No, I meant, I was setting a cookie, then calling session_start() , and
      I was getting an error. Can I call session_start() and then set a
      cookie? I want to set a permanent cookie that will last one million
      seconds. I also want sessions.

      Comment

      • Andy Hassall

        #4
        Re: can I still send cookies after I've called session_start()

        On 21 Jul 2005 08:29:01 -0700, lkrubner@geocit ies.com wrote:
        [color=blue]
        >I was trying to set a cookie before I called session_start() and it was
        >giving me an error.[/color]

        Your post is missing a vital piece of information.
        [color=blue]
        >But isn't sessions really just a cookie? Why would
        >it matter if I sent a cookie before session_start?[/color]

        It doesn't.
        [color=blue]
        >Can I set them afterwards?[/color]

        Yes, and before.

        --
        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

        Comment

        • JDS

          #5
          Re: can I still send cookies after I've called session_start()

          On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
          [color=blue]
          > No, I meant, I was setting a cookie, then calling session_start() , and
          > I was getting an error. Can I call session_start() and then set a
          > cookie? I want to set a permanent cookie that will last one million
          > seconds. I also want sessions.[/color]

          AND WHAT IS THE ERROR????

          sheesh

          --
          JDS | jeffrey@example .invalid
          | http://www.newtnotes.com
          DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

          Comment

          • lkrubner@geocities.com

            #6
            Re: can I still send cookies after I've called session_start()

            [color=blue]
            >On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:[color=green]
            >> No, I meant, I was setting a cookie, then calling session_start() , and
            >> I was getting an error. Can I call session_start() and then set a
            >> cookie? I want to set a permanent cookie that will last one million
            >> seconds. I also want sessions.[/color]
            >
            >AND WHAT IS THE ERROR????[/color]

            This is the error I'm getting:

            <b>Warning</b>: session_start() : Cannot send session cookie - headers
            already sent in
            <b>/home/httpd/vhosts/publicdomainsof tware.org/httpdocs/pdsIncludes/CommandStartSes sion.php</b>
            on line <b>14</b><br />
            <br />
            <b>Warning</b>: session_start() : Cannot send session cache limiter -
            headers already sent in
            <b>/home/httpd/vhosts/publicdomainsof tware.org/httpdocs/pdsIncludes/CommandStartSes sion.php</b>
            on line <b>14</b><br />


            This is line 14 and 15 of CommandStartSes sion:

            session_start() ;
            session_registe r();


            I used my text editor (RedCrimson) and did a search of all the files in
            this project, looking for session_start() . I thought maybe, by
            accident, I was calling it twice. But no, it only appears once.

            Oddly, when I call session_start() , output buffering is on, so I'm not
            sure how I get that error. Later I set a cookie, then I sent a charset
            header indicating that the characters are UTF-8, then I end output
            buffering.

            I thought the output buffering would keep me safe from this kind of
            error, but apparently not.

            Comment

            • lkrubner@geocities.com

              #7
              Re: can I still send cookies after I've called session_start()

              >On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:[color=blue][color=green]
              >> No, I meant, I was setting a cookie, then calling session_start() , and
              >> I was getting an error. Can I call session_start() and then set a
              >> cookie? I want to set a permanent cookie that will last one million
              >> seconds. I also want sessions.[/color]
              >
              >AND WHAT IS THE ERROR????[/color]

              You can see the problem here:

              168体彩幸运飞行艇记录历史全国数据+飞行艇168结果历史记录查询-综合版正规精准计划、飞艇全场实时直播、168官方记录最新现场号码.


              Comment

              • Jerry Stuckle

                #8
                Re: can I still send cookies after I've called session_start()

                lkrubner@geocit ies.com wrote:[color=blue][color=green]
                >>On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
                >>[color=darkred]
                >>>No, I meant, I was setting a cookie, then calling session_start() , and
                >>>I was getting an error. Can I call session_start() and then set a
                >>>cookie? I want to set a permanent cookie that will last one million
                >>>seconds. I also want sessions.[/color]
                >>
                >>AND WHAT IS THE ERROR????[/color]
                >
                >
                > You can see the problem here:
                >
                > http://www.publicdomainsoftware.org/
                >[/color]

                <br />
                <b>Warning</b>: session_start() : Cannot send session cookie - headers already
                sent in

                You're sending <br /> before the session_start call.

                You can't send ANYTHING (including a blank line) before the session_start() call.

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

                Comment

                • Andy Hassall

                  #9
                  Re: can I still send cookies after I've called session_start()

                  On Fri, 05 Aug 2005 21:42:15 -0500, Jerry Stuckle <jstucklex@attg lobal.net>
                  wrote:
                  [color=blue]
                  >lkrubner@geoci ties.com wrote:[color=green][color=darkred]
                  >>>On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
                  >>>
                  >>>>No, I meant, I was setting a cookie, then calling session_start() , and
                  >>>>I was getting an error. Can I call session_start() and then set a
                  >>>>cookie? I want to set a permanent cookie that will last one million
                  >>>>seconds. I also want sessions.
                  >>>
                  >>>AND WHAT IS THE ERROR????[/color]
                  >>
                  >>
                  >> You can see the problem here:
                  >>
                  >> http://www.publicdomainsoftware.org/
                  >>[/color]
                  >
                  ><br />
                  ><b>Warning</b>: session_start() : Cannot send session cookie - headers already
                  >sent in
                  >
                  >You're sending <br /> before the session_start call.[/color]

                  That's part of the PHP error message:

                  andyh@server:/usr/src/php-5.0.4/main$ nl -ba main.c | grep -2 '<br />'
                  736 char *append_string =
                  INI_STR("error_ append_string") ;
                  737 char *error_format = PG(html_errors) ?
                  738 "%s<br />\n<b>%s</b>: %s in
                  <b>%s</b> on line <b>%d</b><br />\n%s"
                  739 : "%s\n%s: %s in %s on line
                  %d\n%s";
                  740 php_printf(erro r_format,
                  STR_PRINT(prepe nd_string), error_type_str, buffer, error_filename,
                  error_lineno, STR_PRINT(appen d_string));

                  --
                  Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                  <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                  Comment

                  Working...