PHP headers_sent() 함수
예시
헤더가 전송되지 않으면 헤더를 전송합니다.
<?php
if (!headers_sent()) {
header("Location: https://www.w3schools.com/");
exit;
}
?>
<html>
<body>
...
...
정의 및 사용
headers_sent() 함수는 헤더가 전송되었는지 여부를 확인합니다.
통사론
headers_sent(file,line)
매개변수 값
Parameter | Description |
---|---|
file | Optional. If the file and line parameters are set, headers_sent() will put the PHP source file name and line number where output started in the file and line variables |
line | Optional. Specifies the line number where the output started |
기술적 세부 사항
반환 값: | HTTP 헤더가 전송된 경우 TRUE, 그렇지 않으면 FALSE |
---|---|
PHP 버전: | 4.0+ |
PHP 변경 로그: | PHP 4.3: 선택적 파일 및 라인 매개변수 추가 |
더 많은 예
예시
선택적 파일 및 라인 매개변수 사용:
<?php
// $file and $line are passed in for later use
// Do not assign them values beforehand
if (!headers_sent($file, $line))
{
header("Location: https://www.w3schools.com/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...
❮ PHP 네트워크 참조