【解決方法】警告: session_start(): セッション Cookie を送信できません – ヘッダーはすでに送信されています

プログラミングQA


こんにちは、ログインしようとすると次のエラーが表示されます

警告: session_start(): セッション Cookie を送信できません – 14 行目の /home/agarwegg/public_html/emailadmin/index.php の (/home/agarwegg/public_html/emailadmin/index.php:1 で出力が開始された) ヘッダーが既に送信されています

警告: session_start(): セッション キャッシュ リミッターを送信できません – 14 行目の /home/agarwegg/public_html/emailadmin/index.php のヘッダーは既に送信されています (出力は /home/agarwegg/public_html/emailadmin/index.php:1 で開始されています)

警告: ヘッダー情報を変更できません – 16 行目の /home/agarwegg/public_html/emailadmin/index.php の (/home/agarwegg/public_html/emailadmin/index.php:1 で開始された出力) によって既に送信されたヘッダー

<!DOCTYPE html>
<?php
    $error = "";
    if(isset($_POST['username'],$_POST['password'])){
 
        /*** You can change username & password ***/
        $user = array(
                        "user" => "abc",
                        "pass"=>"def"          
                );
        $username = $_POST['username'];
        $pass = $_POST['password'];
        if($username == $user['user'] && $pass == $user['pass']){
            session_start();
            $_SESSION['simple_login'] = $username;
            header("Location: Email_Manager.php");
            exit();
        }else{
            $error = "Invalid Login Credentials";
            echo "<script>alert('".$error."'); window.history.back();</script>";
        }
    }
?>

<html>
	<head>
	    <link rel="icon" type="image/png" href="favicon.png">
	     <style>
	     

.header {
   position: absolute;
   left: 0;
   top: 0;
   width: 100%;
 /*  background-color: #4CAF50; */
   font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
   color: white;
   text-align: center;
}
.tableadjust {
   position: fixed;
   margin: auto;
    width: 60%;
   top: 30%;
   margin:auto;
}
</style>   

	<style>

	
	#grad1 {
    height: 200px;
    background: #2939B3; /* For browsers that do not support gradients */
    background: linear-gradient(to right, 	#1385CC , #2939B3); /* Standard syntax (must be last) */
	}
#emails {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    border-collapse: collapse;
    width: 100%; 
    max-width: 512px;  
}

#emails td, #emails th {
    border: 0px solid #ddd;
    padding: 8px;
    color: white;
}

/* #emails tr:nth-child(even){background-color: #f2f2f2;} */

/* #emails tr:hover {background-color: #ddd;} */

#emails th {
    padding-top: 12px;
    padding-bottom: 12px;
    text-align: center;
   /* background-color: #4CAF50; */
    color: white;
  
}
input[type=text], input[type=password], input[type=search] {
      font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    padding: 6px 10px;
    margin: 3px 0;
    box-sizing: border-box;
    border-radius: 25px;
}
    input[type=button], input[type=Submit], input[type=reset] {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
     background-color: Transparent; 
    border-radius: 25px;
    border: 2px solid #FFFFFF;
    color: white;
    padding: 6px 10px;
    text-decoration: none;
    margin: 3px 2px;
    cursor: pointer;
	</style>
	<title>
	Email Management
	</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	
	<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
	</head>
	<body id="grad1"><center>
	<div style="max-width: 512px; width:100%; margin: auto; top: 100px; position: relative;">
        <img src="favicon.png"></img>
	<table id="emails">
		<thead>
			<tr><th colspan=2>Login to Email Management
		</thead>
		<tbody>
			<form method=POST action="index.php">
			<tr><td>Username: <td><input placeholder="Username" name="username" type="text" style="width:100%">
			<tr><td>Password: <td><input placeholder="Password" name="password" type="password" value="" style="width:100%">
			<tr><td colspan=2><input type="submit" value="Login" style="width:100%">
		</tbody>

	</table>
<font face = "Trebuchet MS" color=white><p style="width: 100%">Powered by <a href="http://www.byteitcorp.com" style="color:white;">ByteIT Corp</a></p></font>
	</div>
	

  

	</center>
	

<div class="header">
  <p><font size=25>EMAIL MANAGER</font></p>
</div>

	</body>
	
	</html>

私が試したこと:

@ob_start(); を入れてみました。 コードの先頭に

解決策 1

あなたの <!DOCTYPE html> が問題です。 出力できない場合があります どれでも ヘッダーを送信するものの前の HTML (Cookie など)。 の <?php タグはファイルの最初のものでなければなりません。 その前に空白さえありません。 それは永遠にそうでした。 PHP 7 の問題ではありません。

解決策 4

Connected successfully
Warning: session_start(): Cannot start session when headers already sent in /storage/emulated/0/Web Serber/login.php on line 11

コメント

タイトルとURLをコピーしました