session data / header question?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizardry
    New Member
    • Jan 2009
    • 201

    session data / header question?

    hello -

    if session is started from the same page, and i have another script that needs to access header data with out destorying the session data.

    a. should i store the header info in variables on the page then access them by the var in the page that needs them?

    error desc:

    currently if the session has started and that script is executed it resends the header info which appearantly destroys the session and errors "saying headers alread sent".

    thanks in advance for your help.

    theo e. werntz ii
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    I think you may be misunderstandin g how headers and sessions work. Or I may be misunderstandin g your post. Either way, this is how session do work.

    A session has little to do with the actual headers. It only sends a session ID via a cookie (or in rare cases a GET parameter, but that is irrelevant here) - which is why it must be able to set a header. If you call session_start() again from within the same PHP page, or any PHP page included into that page, then it would have no effect.

    If - after said page has been sent and the cookie has reached the client - the client does another request (via AJAX, for example) the session ID int the cookie will be sent to the server and the previously used session will be restored.

    If you are getting a "headers already sent" warning and you session data is not being set, then odds are that your first call to session_start is failing. That error means that the headers can not be set because they have already been sent to the client, meaning the session cookie can not be sent.

    Comment

    • wizardry
      New Member
      • Jan 2009
      • 201

      #3
      thanks for the reply -

      here are the errors:

      cannot send session cookie - headers already sent by
      cannot send session cache limiter - headers already sent by

      i have an a script that is loaded from when it is first access.

      i.e. www.domain.com -- loads then the script loads when its is threaded.

      then the session server will start once the login form has been accessed on the same page.

      i've tried adding that below the session marker but it gets the same error. meaning have the session loaded first on the page.

      i know that session is working correctly, im able to access objects with that session data.

      -- also not to get off topic do you have a good article on cookies?

      thanks in advance for your help.

      Comment

      • wizardry
        New Member
        • Jan 2009
        • 201

        #4
        also the page that im having the problem is the index. the rest of the pages that i need that script on and they use sessions are working fine.

        thanks, again in advance for your help!

        Comment

        • nilayanand
          New Member
          • Nov 2006
          • 10

          #5
          Just make sure, you do not output anything before calling session_start() .

          Comment

          • wizardry
            New Member
            • Jan 2009
            • 201

            #6
            nothing was outputed before the session start.

            session start is at the begining of the page.

            i.e.
            Code:
            if (!isset($_Session))
            {
            session_start();
            }
            ?>
            <!-- here is the script to be called after. -->
            <?php require_once('script.php'); ?>
            
            -- html / and css -- not posting not needed for this debugging help.
            Ok as i posted earlier this way works on the rest of the site. excluding the INDEX.php

            my question is why has it worked on all of the other pages but not the INDEX.php

            i've tried moving the session_start module to the top or where the function needs it. but nothing. same issue. i've tried putting the script that needs to be ran before or after the session call to start. but same error.

            Session do work. I use them and are able to output their variables on a echo "$_session" ;

            thanks, again in advance for your help.

            Theo Werntz II

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Hey.

              The session super-global is called $_SESSION, not $_Session or $_session, or any other variation thereof. It has to be all upper-case. (Variable names in PHP are case-sensitive.)

              If you use the incorrect case PHP will just treat it as a typical variable, and create a normal array for you. It will work just fine on that page, but won't be stored between requests.

              Comment

              • wizardry
                New Member
                • Jan 2009
                • 201

                #8
                hey alti -

                its not the variable case size. it is in case upper format.

                could you re-read the previous post?

                have you ran into any problems with index.php with using sessions?

                sessions work through out the rest of the site? but not the index for this script. it works fine with out it but not with it added.


                Thanks, in advance for your help!

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  Originally posted by wizardry
                  its not the variable case size. it is in case upper format.
                  I only mentioned that because your example code used a mixed-case version of it, which would be invalid.
                  In any case, if you are sure this is not the problem, I'm inclined to agree with nilayanand.

                  Can you post the entire beginning of the index.php, up to the point you call the session_start function?
                  The "headers already sent" error tells us there is something being sent to the browser before the function is called. We must find out what and remove it.

                  You can check out this article draft which Markus has been working on. It explains this problem in details.

                  Originally posted by wizardry
                  hey alti
                  It's Atli, by the way ;-)
                  (It seems most people want to put the L first. I don't know why xD)

                  Comment

                  • wizardry
                    New Member
                    • Jan 2009
                    • 201

                    #10
                    thanks for the reply atli -

                    ok the code is their nothing else was copied besides where i was having the error.

                    i'm doing some more debugging.

                    thanks again for your help. will repost later currently working on this img loop array problem im having. can you look at the other post for me in forums php img loops?

                    Comment

                    Working...