Re: Warning: session_start()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 18, 2011 at 7:15 PM, Nazish <nazish@xxxxxxx> wrote:

> Hi everyone,
>
> I recently uploaded my website files to a server. When I tried to log into
> my website, I received these error messages:
>
> *Warning*: session_start()
> [function.session-start<http://www.myparcoasis.com/function.session-start
> >]:
> Cannot send session cookie - headers already sent by (output started at
> /home2/myparcoa/public_html/index.php:10) in *
> /home2/myparcoa/public_html/includes/login_form.php* on line *33*
>
> *Warning*: session_start()
> [function.session-start<http://www.myparcoasis.com/function.session-start
> >]:
> Cannot send session cache limiter - headers already sent (output started at
> /home2/myparcoa/public_html/index.php:10) in *
> /home2/myparcoa/public_html/includes/login_form.php* on line *33*
>
> *Warning*: Cannot modify header information - headers already sent by
> (output started at /home2/myparcoa/public_html/index.php:10) in*
> /home2/myparcoa/public_html/includes/login_form.php* on line *36*
> *
> *
>
> The website worked fine on the Apache localhost server (I could log in), so
> I'm not sure what's wrong with the code which is creating the error on the
> online server. Any ideas? I've highlighted the two error lines (31 & 34).
> I'd appreciate any insight! Thnx!
>
>
> <!-----------------------------------------------------------------------
>            WHEN USER CLICKS 'ENTER' TO LOGIN
> <!------------------------------------------------------------------------>
> <?php
>
> $submit = ($_POST['submit']);
>
> if ($submit)  // If user clicks the 'ENTER' button to login
> {
>    // Connect to server and select database
>    include ("includes/mysql_connect.inc");
>    include ("includes/connect_res_directory.php");
>
>    // define login variables
>    $login = mysql_real_escape_string($_POST['login']);
>    $password = mysql_real_escape_string($_POST['password']);
>
>    $check_login = mysql_query("SELECT * FROM unit_info
>                               WHERE login = '$login'
>                               AND password = '$password'");
>
>    $data = mysql_fetch_assoc($check_login);
>
>    // Are all the fields filled?
>    if($login && $password)
>    {
>        // If fields are entered, verify username and password in mysql
> database
>        if (mysql_num_rows($check_login)) // If the login and password
> exists
>        {
>            //Login
>           * session_start();*
>            $_SESSION ['login'] = $data['login'];
>
>        *    header ("Location: index_test.php"); // webpage for correct
> login*
>
>            exit;
>        }
>        else
>        {
>            // Invalid username/password
>            echo "<div class='alert'>The username or password you entered is
> incorrect.</div>";
>        }
>    }
>    else
>        echo "<div class='alert'>Please enter all the fields!</div>";
>
> }
>
> ?>


Compare your configuration files. The option that's likely different here
is output_buffering. See the manual for full details:
http://php.net/outcontrol.configuration

To avoid this in future I suggest you make sure the configuration you're
running in production matches that which you're running in development,
other than display_errors (off or to a file in production, on in dev). In
fact it doesn't really matter if they're different so long as you know
what's different, why and that the code you write can cope with both, but
I'd recommend they're as similar as is logical.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux