Грешка: Cannot modify header information

  • Автор Автор boby
  • Начална дата Начална дата

boby

Registered
Кодът е простоват. Тук:
Код:
<php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
        <title>Логни се</title>
    </head>
    <body>
        <?php
        if($_SESSION['is_logged']==true)
                {
                    echo '<a href="izlez.php">Излизай и затваряй вратата!</a>';
                }
                else
                {
                    $ime=trim($_POST['ime']);
                    $password=trim($_POST['password']);
                    if(strlen($ime)>3 && strlen($password)>3)
                    {
                        if($ime=="jojomojo" && $password=="mojojojo")
                        {
                            $_SESSION['is_logged']=true;
                            header("Location: index.php");
                        }
                        else
                        {
                            echo "Върни се, нещо си объркал!";
                        }
                    }
                }
                ?>
                <form method="post" action="index.php">
                Потребителско име: <input type="text" name="ime"><br>
                Парола: <input type="password" name="password"><br>
                <input type="submit" value="Влез бързо!">
                </form>
                                <php
                }
        ?>
    </body>
    </html>

изкарва тази грешка:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\loginsys\index.php:11) in C:\xampp\htdocs\loginsys\index.php on line 26

Как да я оправя?
Мерси.
 
<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Логни се</title>
</head>
<body>
<?php
if($_SESSION['is_logged']==true)
{
echo '<a href="izlez.php">Излизай и затваряй вратата!</a>';
}
else
{
$ime=trim($_POST['ime']);
$password=trim($_POST['password']);
if(strlen($ime)>3 && strlen($password)>3)
{
if($ime=="jojomojo" && $password=="mojojojo")
{
$_SESSION['is_logged']=true;
header("Location: index.php");
}
else
{
echo "Върни се, нещо си объркал!";
}
}
}
?>
<form method="post" action="index.php">
Потребителско име: <input type="text" name="ime"><br>
Парола: <input type="password" name="password"><br>
<input type="submit" value="Влез бързо!">
</form>
<php
}
?>
</body>
</html>
 
<?
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Логни се</title>
</head>
<body>
<?php
if($_SESSION['is_logged']==true)
{
echo '<a href="izlez.php">Излизай и затваряй вратата!</a>';
}
else
{
$ime=trim($_POST['ime']);
$password=trim($_POST['password']);
if(strlen($ime)>3 && strlen($password)>3)
{
if($ime=="jojomojo" && $password=="mojojojo")
{
$_SESSION['is_logged']=true;
?>
<meta http-equiv="refresh" url=index.php">
<?
}
else
{
echo "Върни се, нещо си объркал!";
}
}
}
?>
<form method="post" action="index.php">
Потребителско име: <input type="text" name="ime"><br>
Парола: <input type="password" name="password"><br>
<input type="submit" value="Влез бързо!">
</form>
<php
}
?>
</body>
</html>
 
Код:
<?php
ob_start();
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
        <title>Логни се</title>
    </head>
    <body>
        <?php
        if($_SESSION['is_logged']==true)
                {
                    echo '<a href="izlez.php">Излизай и затваряй вратата!</a>';
                }
                else
                {
                    $ime=trim($_POST['ime']);
                    $password=trim($_POST['password']);
                    if(strlen($ime)>3 && strlen($password)>3)
                    {
                        if($ime=="jojomojo" && $password=="mojojojo")
                        {
                            $_SESSION['is_logged']=true;
                            header("Location: index.php");
                        }
                        else
                        {
                            echo "Върни се, нещо си объркал!";
                        }
                    }
                }
                ?>
                <form method="post" action="index.php">
                Потребителско име: <input type="text" name="ime"><br>
                Парола: <input type="password" name="password"><br>
                <input type="submit" value="Влез бързо!">
                </form>
                                <php
                }
        ?>
    </body>
    </html>
 

Back
Горе