Web Analytics Made Easy -
StatCounter sessions error - CodingForum

Announcement

Collapse
No announcement yet.

sessions error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sessions error

    OK, first time using sessions. Help me out here. Im using a sessions code (below) to store the username in a session cookie...







    PHP Code:
    session_register("$username"); 




    I get this when its being processed:


    Warning: session_register(): Cannot send session cookie - headers already sent by (output started at /var/www/html/forum/php/newthreadprocessor.php:7) in /var/www/html/forum/php/newthreadprocessor.php on line 241

    Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at /var/www/html/forum/php/newthreadprocessor.php:7) in /var/www/html/forum/php/newthreadprocessor.php on line 241




    The session code(above) is being processed on tthe same page as forum data within the same delimiter. I'm guessing that might have something to do with this error.

    What can I do to correct this?
    ~Designer's Toolz~

  • #2
    Hi,

    You don't seem to use session_start at the beginning of your script... so session_register works like session_start. And session_start has to be put at the very beginning of your whole script. It modifies the header - as the error message told you - and you can't modify headers if they are already sent to the browser.

    So it's recommandable to use session_start at the beginning of your script, then you can use session_register later without problems.

    http://php.net/session_register
    If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made.

    http://php.net/session_start
    Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.
    Further, you have to register your variables with their name, and not with their content. So, use this Line to register $username:

    PHP Code:
    session_register("username"); 
    Saludo
    piz
    www.united-scripts.com
    www.codebattles.org

    Comment


    • #3
      I guess I should also point out that session_register is no longer in use. You'll need to use

      PHP Code:
      session_start();
      $_SESSION['username'] = $username

      Comment


      • #4
        Originally posted by Nightfire
        [B]I guess I should also point out that session_register is no longer in use. You'll need to use
        Oh... I know that it's recommended to use the other way. But what do you mean by "not longer in use"? They'll remove the function in PHP5?
        www.united-scripts.com
        www.codebattles.org

        Comment


        • #5
          It just makes it more compatible. session_register (register_globals) have been turned off by default since 4.2.0, which means that session_register won't work, but the superglobals, such as $_SESSION will work with register_globals turned on or off

          Comment


          • #6
            i used:

            PHP Code:
            <?php
            session_start
            ();
            $_SESSION['sessionusername'] = $username;
            ?>


            and I get..



            ..
            Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/html/forum/php/newthreadprocessor.php:7) in /var/www/html/forum/php/newthreadprocessor.php on line 8

            Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/www/html/forum/php/newthreadprocessor.php:7) in /var/www/html/forum/php/newthreadprocessor.php on line 8


            which is the same thing basically so that didnt help at all....and this is at the top of the script.
            ~Designer's Toolz~

            Comment


            • #7
              hey yall im sorry....when you said beginning.....you ment beginning....before <html>. very first thing in the page is to start the session. anyway it works now thanks.
              ~Designer's Toolz~

              Comment


              • #8
                is it possible to hold two session variables at the same time? ( password and username) thanks
                ~Designer's Toolz~

                Comment


                • #9
                  @DsgnrsTLZAdmin: Yes, you can.

                  It just makes it more compatible. session_register (register_globals) have been turned off by default since 4.2.0, which means that session_register won't work, but the superglobals, such as $_SESSION will work with register_globals turned on or off
                  Thx. Yes, that's what I know, too.
                  www.united-scripts.com
                  www.codebattles.org

                  Comment

                  Working...
                  X