Results 1 to 8 of 8

Thread: Is wrong have two statements like: <?php session_start(); ?>

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Is wrong have two statements like: <?php session_start(); ?>

    Is wrong have two statements like:
    <?php session_start(); ?>
    in a document ?

    34.<?php session_start(); ?>

    the error below appears at
    http://www.poliscarhire.com/administ...-webmaster.php
    has any to do with https:// ? No session var above line 34 ...


    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/p/o/l/polisch123/html/administration/webmaster/contact-webmaster.php:7) in /home/content/p/o/l/polisch123/html/administration/webmaster/contact-webmaster.php on line 34

  2. #2
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    From an output standpoint, its not wrong. Once the parsing starts and on the first encounter of session_start() in a script, the headers will be sent for that particular page(stand alone script), any further session_start() encounters will just be ignored and will result in a warning, and ideally this will have no effect on output.

    You can use <?php error_reporting(0); ?> on ur script to hide these warnings/errors.

    Best,
    Kris

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I don't believe the errors you are getting are caused by having two session_start(); on your page. I believe that something must be getting sent to the user's browser prior to the first session_start(); call.

    Remember, there can be nothing sent to the user prior to calling session_start(); Not even one space.

    For example, the following put at the top of a file won't work

    Code:
     <?php session_start(); ?>
    because there is a space in front of <?php .

    You either have a space, tab, or some html being sent out prior to the first session_start();

    I think.....

    If you could post all the php code for that page, we could be sure.

    Good Luck,

    Jason

  4. #4
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Hi JasonDFR,

    I do not think having session_start(); anywhere even in the middle of a script with or without space will have the effect as what you have suggested. The following code will still print "Hello World".
    PHP Code:
    <?php
    error_reporting
    (1);

    $_SESSION['msg'] = "Hello World";

                      
    session_start();

    echo 
    $_SESSION['msg'];
    ?>

    @leonidassavvides,

    I think its because of duplicate usage of session_start();


    Rgds,
    Kris

  5. #5
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    White space or HTML code before the <?php tag will result in the error he is getting when you call session_start();

    I was not referring to any whitespace inside the <?php block. That is why I said "sent to the user." I probably should have said browser.

    Regarding calling session_start(); twice:

    http://www.php.net/function.session-start

    "As of now, calling session_start() while the session has already been started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored."

    His error is a warning, not E_NOTICE. His page has sent header information to the browser prior to calling the first session_start();

    I am sticking to my previous diagnosis.

    Maybe some of the more experienced guys will chime in here.

  6. #6
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Quote Originally Posted by l_kris06 View Post
    Hi JasonDFR,

    I do not think having session_start(); anywhere even in the middle of a script with or without space will have the effect as what you have suggested. The following code will still print "Hello World".
    PHP Code:
    <?php
    error_reporting
    (1);

    $_SESSION['msg'] = "Hello World";

                      
    session_start();

    echo 
    $_SESSION['msg'];
    ?>
    And by the way, your code above will not output "Hello World". The session has to be started before you set any session variables.

  7. #7
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    You are right, Thanks for pointing out.
    PHP Code:
    <?php
    session_start
    ();
    error_reporting(1);
    $_SESSION['msg'] = "Hello World";
    session_start();
    echo 
    $_SESSION['msg'];
    ?>

    @leonidassavvides,

    I think at line 34, u have used another session_start().
    Can you post the code for "contact-webmaster.php".

    Best,
    Kris

  8. #8
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Yeah, post the php source for that page.

    l_Kris,

    Having two session_start(); will not result in the error he is getting. Have you visted his page and read the error at the top of it?

    Most php configurations have level E_NOTICE messages turned off by default, thus putting two session_start(); in one page will not result in any error message being sent to the browser.

    I am sure his error is not caused by two session_start(); calls. If I am wrong I'll definitely learn something new.

    Post the code please.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •