如何解決PHP ??: ?? ??? ??? ? ????. ??? ???? ??? ???? ???? ???????.
Aug 18, 2023 pm 01:46 PMPHP ?? ?? ??: ?? ??? ??? ? ???? - ???
?? ??? ???? ?? ???????. PHP ??????? ??? ? "?? ??? ??? ? ???? - ??? ???? ??? ???? ?? ???????."?? ?? ???? ???? ??? ????. ". ? ?? ???? ????? ??????? ???? ??? ??? ??? ????. ? ????? ? ??? ???? ??? ???? ? ?? ?? ??? ?????.
?? ? ?? ???? ??? ????? ??? ???. "?? ??? ??? ? ????"? HTTP ?? ??? ????? ??? ?? ?? ?? ???? ????? ?????? ?????. ????? HTTP ?? ??? PHP ???? ???? header()
??? ???? ?? ??? ??, ????? ?? ????. ??? ?? ??(??, ? ??, ?? ??? ? ??)?? ?? ? ?? ???? ?????. header()
函數(shù)來(lái)設(shè)置,例如設(shè)置響應(yīng)內(nèi)容的類型、重定向等等。然而,如果在這之前有任何輸出內(nèi)容(包括空格、換行、錯(cuò)誤消息等),就會(huì)導(dǎo)致這個(gè)警告消息。
警告消息的具體內(nèi)容一般會(huì)包含"output started at",表示在哪個(gè)文件的哪一行開始輸出了內(nèi)容。這個(gè)提示能夠幫助我們定位到問(wèn)題所在。
那么,如何解決這個(gè)問(wèn)題呢?以下是幾種常見的解決方案。
- 檢查文件編碼和文件格式:確保PHP文件的編碼格式是UTF-8,并且沒(méi)有BOM(Byte Order Mark)標(biāo)記。有時(shí)候,一些編輯器會(huì)自動(dòng)在文件開頭添加BOM標(biāo)記,這會(huì)導(dǎo)致輸出內(nèi)容被發(fā)送到瀏覽器,從而引發(fā)警告。可以使用專門的文本編輯器,如Notepad++,來(lái)檢查和修改文件編碼。
- 檢查空格和換行:確保在
<?php
標(biāo)簽之前沒(méi)有空格和換行。在header()
函數(shù)之前的任何空格或換行都會(huì)被視為輸出內(nèi)容,并觸發(fā)警告。
下面是一個(gè)示例代碼,演示了此問(wèn)題的常見原因和解決方案:
<?php // 錯(cuò)誤示例 - 會(huì)產(chǎn)生警告 echo "Hello World!"; header("Location: http://example.com"); exit; // 解決方案 - 移除輸出內(nèi)容前的空格和換行 <?php header("Location: http://example.com"); exit; // 解決方案 - 使用輸出緩沖區(qū) <?php ob_start(); // 啟動(dòng)輸出緩沖區(qū) echo "Hello World!"; header("Location: http://example.com"); exit; ob_end_flush(); // 刷新緩沖區(qū)并發(fā)送內(nèi)容給瀏覽器 // 解決方案 - 修改文件編碼和格式 <?php ob_start(); // 啟動(dòng)輸出緩沖區(qū) echo "Hello World!"; header("Location: http://example.com"); exit; ob_end_flush(); // 刷新緩沖區(qū)并發(fā)送內(nèi)容給瀏覽器 // 解決方案 - 使用die()或exit()函數(shù)代替header()函數(shù) <?php echo "Hello World!"; die("Location: http://example.com"); ?>
綜上所述,當(dāng)出現(xiàn)"Cannot modify header information - headers already sent by output started at"的警告消息時(shí),我們可以通過(guò)檢查文件編碼和文件格式、移除輸出內(nèi)容前的空格和換行、使用輸出緩沖區(qū)、或者使用die()
或exit()
函數(shù)來(lái)解決問(wèn)題。重要的是要注意在header()
- ?? ??? ? ?? ?? ??: PHP ??? ??? ??? UTF-8?? BOM(Byte Order Mark) ??? ??? ?????. ??? ?? ?? ???? ?? ?? ??? BOM ??? ???? ???? ?? ???? ????? ???? ??? ???? ??? ????. Notepad++? ?? ?? ??? ???? ???? ?? ???? ???? ??? ? ????.
- ?? ? ??? ??:
<?php
?? ?? ???? ???? ??? ?????.header()
?? ?? ???? ? ??? ?? ???? ???? ??? ??????.
die()
?? exit() ??? ???? ?????. ? ??? ????? <code>header()
?? ?? ??? ??? ?? ???? ?? ?????. ??? ???? ??? ? ?? ??? ??? ???? ??????? ???? ??? ??? ? ????. ??? ??? 如何解決PHP ??: ?? ??? ??? ? ????. ??? ???? ??? ???? ???? ???????.? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)
![PHP ??: filesize() [function.filesize]: ?? ?? ???](https://img.php.cn/upload/article/000/887/227/168744929486784.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
PHP ????? ??? ? ?? ??? ??? ??? ?? ???? ?? ? ??? "PHPWarning: filesize()[function.filesize]:statfailed"?? ?? ??????. ? ?? ???? ?? ???? ????? ?? ???? ?? ??? ????. ? ????? ?? ???? ??? ??? ??? ? ??? ??? ?? ??? ?????. ??? ??? PHP, ?? ??? ????.

PHPWarning ?? ??: file_get_contents(): ?? ??? ?? ? ????. PHP ?? ???? ??? ?? ?? ???? ?? ?????. PHPWarning: file_get_contents(): ?? ??? ?? ? ????. ? ??? ????? file_get_contents ??? ??? ? ?????.

PHPWarning:fopen():failedtoopenstream:Permissiondenied ?? ?? ?? PHP ????? ???? ???? PHPWarning:fopen():failedtoopenstream:Permissiondenied? ?? ?? ???? ?? ??? ???. ? ??? ????? ??? ?? ?? ???? ???? ?? ?????.

PHP? ???? ????? ????? ??? ? ?? ?? ?? ???? ??? ? ????: PHPWarning:Cannotmodifyheaderinformation. ? ??? ????? ???? ??? ?? HTTP ??? ????? ??? ? HTTP ??? ????? ?? ? ?????. ? ??? ??? ??? ?? ?? ??? PHP ??? ??? ?? ??? ??? ? ????. ? ??? ???

PHP?? ?? ??: ?? ??-??? ?? ?? ???? ???????. PHP ??????? ??? ? "?? ??-??? ?? ???????. p? ??? ? ????"?? ?? ???? ???? ??? ????.

PHPWarning:Divisionbyzero ??? ???? ?? PHP ?? ???? ?? "PHPWarning:Divisionbyzero" ?? ???? ?? ?????. ? ??? ??? ???? ??? ??? 0?? ??? ??? ??? ?????. ???? ??? ??? ???? ??? ???? ????? ???? ??? ??? ????. ??? ???? ? ??? ???? ?? ? ? ?? ?? ????. ???? ???

PHPWarning: ?? ??? ??? ? ????.-??? PHP? ???? ?? ????? ???? ?? ??? "?? ??? ??? ? ????. ?? ??? ?? ???????."?? ?? ???? ?????. ? ?? ???? ????? ??? ??? ??? ? HTTP ?? ??? ????? ??? ? ?????. ? ??? ???

PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectoryinfile.phponlineX? ???? ?? PHP ????? ???? ??? ? ??? PHPWarning:fopen():failedtoopenstream:Nosuchfileor? ?????.
