运行我的脚本时,我收到几个这样的错误:
警告:不能更改头信息-头已经发出(输出开始/some/file.php:12)在/some/file.php上线23
错误消息中提到的行包含header()
和setcookie()
调用.
这可能是什么原因?以及如何解决它?
可能重复:
PHP 已发送的标头
为什么我不能摆脱这个错误:警告:无法修改标头信息 - 标头已经发送(输出开始于 /Applications/XAMPP/xamppfiles/htdocs/login.php:43)在 /Applications/XAMPP/xamppfiles/htdocs /login.php 第 24 行
第 24 行是带有简单括号的行。我寻找了额外的空格,因为这些是导致此错误的常见原因(从我读过的内容来看),但我找不到任何空格。有任何想法吗?
这是我的代码:
<?php
$check = 0;
if (isset($_POST['submit']))
{
$username = htmlentities($_POST['name']);
$username = strtolower($username);
$password = htmlentities($_POST['apw']);
$filename = getcwd() . "/passwd.txt";
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
foreach($lines as $key => $line)
{
list($name, $pw) = explode(':', $line);
if($name == $username && $pw == $password)
{
$check++;
break;
}
}
if ($check == 1){
checkifPlayed($username);
}
else{
printf("Your username or password are invalid. …
Run Code Online (Sandbox Code Playgroud)