가능한 중복 :
“Warning: Headers already sent” in PHPPHP는 OOP : 헤더가 이미
I, 나는이 스크립트에서 헤더를 설정하기 전에 텍스트를 출력 아니에요 100 % 확신하지만, 이 오류가 발생합니다. Index.php는의
warning: Cannot modify header information - headers already sent by (output started at /home/x/public_html/index.php:4) in /home/x/public_html/core/functions.php on line 25
최고
<?php
require_once "core/functions.php";
$actions = new Actions();
$actions->isUserLogged($_SERVER['REMOTE_ADDR'], $_COOKIE['cData']);
?>
<!DOCTYPE html>...
코어/functions.php
<?php
include_once('connection.php');
class Actions {
private $db;
public function __construct() {
$this->db = new Connection();
$this->db = $this->db->dbConnect(mysql info);
}
public function isUserLogged($currentIP, $cData) {
if(!empty($cData)){ //if cookie is not empty
$getData = $this->db->query("SELECT loggedIP FROM registery WHERE session='".$cData."'")->fetchColumn(); //finding entry in registery.
$loggedIP = $getData['loggedIP'];
if($currentIP == $loggedIP) {return true;} //if that loggedIP and currentIP matces -> proceed.
else { return setcookie('cData','',time()-31536000); //this is where the error points.
return header("location: login.php");} // else unset cookie and redirect to login.
} else {
return header("location: login.php");
}
}
}
?>
connection.php
<?php
error_reporting(E_ALL);
class Connection {
public function dbConnect($server, $username, $password, $db){
return new PDO('mysql:host='.$server.';dbname='.$db, $username, $password);
}
}
?>
사람이 좀 걸릴 너무 친절 될 경우 내 실수를 찾아 낼 시간이야. 바바는 "위해서는 ini_set을 사용하도록 제안
솔루션 ("display_errors를 "을"On "으로);" 그리고 마술처럼 그 문제를 해결했습니다 ... 나는 왜 모두 ty일까요? :-)
표시되는 오류가 있습니까? 표시 오류 행을 주석 처리하십시오. – Cups
어떤 출력도이 오류를 유발합니다. 여기에는 공백 (공백, CRLF 등) 및 바이트 순서 표시가 포함됩니다 (파일이 유니 코드로 인코딩 된 경우 바이트 순서 표시가 없음을 확인하십시오). – Ynhockey
나는 html 코드를 인쇄 한 후에 session_start, cookie_set 또는 header *를 사용했다고 생각한다. html 코드를 인쇄 할 때 "200 OK, content type text/html"이라는 헤더를 보내고이 헤더를 수정하려는 함수는 불가능합니다. – artragis