• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

session start verhindert sich selbst?!

Status
Für weitere Antworten geschlossen.

Folon

Neues Mitglied
Also ich habe ein Problem, dass bei einem folgenden Code immer der Fehler kommt, dass die session bereits auf zeile 15 aktiviert wurde, dabei ist der session_start() befehl auf zeile 15
HTML:
    <head>


        <title>Owned!</title>


        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />

        <meta name="description" content="" />

        <meta name="author" content="" />

        <meta name="keywords" content="" />

        <meta name="generator" content="Webocton - Scriptly" />

        <meta http-equiv="refresh" content="1; URL=index.php" />
        <?php

            session_start();

        ?>
        <style type="text/css">

            body {

                font-size:100px;

                color:<?php if ( $_SESSION['tblack'] == true ) { echo 'white'; 

$_SESSION['tblack'] == false; } else { echo 'black'; $_SESSION['tblack'] == 

true; } ?>;
                background-color:<?php if ( $_SESSION['bblack'] == true ) { echo 'black'; $_SESSION['bblack'] == false; } else { echo 'white'; $_SESSION['bblack'] == true; } ?>;
                text-align:center;
            }
        </style>



    </head>

    <body>
        <p>...Inhalt...</p>
    </body>

</html>
Als Fehler kommt
(Quellcode)
Code:
<html> 
    
        <title>Owned!</title> 
    
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 
        <meta name="description" content="" /> 
        <meta name="author" content="" /> 
        <meta name="keywords" content="" /> 
        <meta name="generator" content="Webocton - Scriptly" /> 
        <meta http-equiv="refresh" content="1; URL=index.php" /> 
        <br /> 
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\1\index.php:10) in <b>C:\xampp\htdocs\1\index.php</b> on line <b>15</b><br /> 
<br /> 
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\1\index.php:10) in <b>C:\xampp\htdocs\1\index.php</b> on line <b>15</b><br /> 
        <style type="text/css"> 
            body {
                font-size:100px;
                color:black;
                background-color:white;
                text-align:center;
            }
        </style> 
        
        
    
    </head> 
    
    <body> 
        <p>...Inhalt...</p>    
    </body> 
 
</html>
 
session_start setzt ein Cookie. Dazu muss PHP einen HTTP-Header senden. Der muss aber immer zwingend am Anfang vor dem Inhalt der Seite kommen. D gibst aber vor diesem Header bereits HTML aus.

Daher kommt die Fehlermeldung "Headers already sent".
 
Status
Für weitere Antworten geschlossen.

Neueste Beiträge

Zurück
Oben