0

I tried some solution from internet, I put session_start(); at first line, also try by using @ob_start(); Any other solution??? My code is here:

<?php
session_start();
require_once('page.inc');  

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>site 1</title>
<meta name="keywords" content="universe, blog theme, black, website template, templatemo" />
<meta name="description" content="About Universe, Our Company, free website template" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="js/jquery-1.6.3.min.js" ></script>


</head>
<body>
<?php
if(!isset($_SESSION['loggedinuser']))
{
if (isset($_POST['Signin']))
{
$username=$_REQUEST['username'];
if($username=='a')
$_SESSION['loggedinuser']=$username;
else
echo " the username or password you entered do not matchted ! ";

}
else
{
?>
 <form  method="post" action="index.php" >
<input type="text" name="username" id="username" > 
<input name="Signin" type="submit" value="Signin" />
</form>
<?

}
}
    else
    //something else
?>
    </body>
    </html>

here the error is:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /usr/local/apache2/htdocs/jasi/medu_quiz_22111_bl/index.php:1) in /usr/local/apache2/htdocs/jasi/medu_quiz_22111_bl/index.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /usr/local/apache2/htdocs/jasi/medu_quiz_22111_bl/index.php:1) in /usr/local/apache2/htdocs/jasi/medu_quiz_22111_bl/index.php on line 2

2 Answers2

1

Check whitespaces before <?php, ensure that the <?php is the first character, not tabbed or spaced.

Taalaibek M
  • 101
  • 4
0

I have tried your code and all works fine, I copied pasted it as is and the form is showing normal

even submitted the form twice once with the correct value and form disappeared and once with the wrong value and the message that it is a wrong value

if you have placed some white space before :

        <?php
        session_start();
        ....
        ?>

That might produce an error, nothing should come before the session_start() part, maybe you have note created the page: page.inc and that is doing the damage

This is the new code I tried, and these are step you can take:

I have checked it with opera, yes at first it was not showing, but with a heavy refresh it did show, try to do a no caching mechanism, by maybe sending it to page with a random id, this will clear the cache, the problem is not session in opera, the session is working, it is in caching,

Refresh your opera and you will, I took the address and copied it into another tab on opera, and the session showed, This is the complete copy on my version:

        <?php
        session_start();
        require_once('page.inc');  

        ?>

        ........

        <?php
        if(!isset($_SESSION['loggedinuser']))
        {
            if (isset($_POST['Signin']))
            {
                $username=$_REQUEST['username'];
                if($username=='a')
                $_SESSION['loggedinuser']=$username;
                else
                echo " the username or password you entered do not matchted ! ";

            }
            else
            {
            ?>
             <form  method="post" action="index.php" >
                    ......
            </form>
            <?

            }
        }
        else if(isset($_SESSION['loggedinuser']))
        {
                $ses = $_SESSION['loggedinuser'];
                echo "LINE 47 session is $ses ";
        }
        else
        {
            $ses2 = $_SESSION['loggedinuser'];
            echo "LINE 51 session is $ses2 ";

        }
        ?>

            </body>
            </html>

This produces:

Line 2 included a page LINE 47 session is a 56

page.inc

        <?php
        echo " Line 2 included  a page ";
        ?>
Peter Manoukian
  • 158
  • 1
  • 13
  • This code is running from 5 month, although the warning was seen. but suddenly it stops to create session......I cant find out the problem..... – user3129375 Dec 10 '14 at 08:00
  • Your code on Line 44: else { I have added this : else { $ses = $_SESSION['loggedinuser']; echo "session is $ses "; } It is displaying correctly: session is a – Peter Manoukian Dec 10 '14 at 08:06
  • Yes it is happening for Opera for me. but not for Mozilla and google chrome !! really its such a problem I have never faced !! – user3129375 Dec 10 '14 at 08:09
  • 1
    I have checked it with opera, yes at first it was not showing, but with a heavy refresh it did show, try to do a no caching mechanism, by maybe sending it to page with a random id, this will clear the cache, the problem is not session inopera, the session is working, it is in caching, refresh your opera and you will, I took the address and copied it into another tab on opera, and the session showed, This is the complete copy on my version, I will add on the answer, I appreciate if you mark my question as useful or the right answer – Peter Manoukian Dec 10 '14 at 08:19