更新時(shí)間:2021-11-08 編輯:創(chuàng)始人 關(guān)注人次:0 云搜索
<?php $user=$_GET['username']; echo $user; ?>
直接運(yùn)行改php腳本的話會(huì)出現(xiàn)”
Notice: Undefined index: username in D:wamp\test\test.php on line 2”的警告,但這是PHP 的提示而非報(bào)錯(cuò),這里我未給$user賦予值,就把它輸出,所以報(bào)錯(cuò)了。PHP 本身不需要事先聲明變量即可直接使用,但是對未聲明變量會(huì)有提示。在網(wǎng)站正式開始運(yùn)行時(shí),會(huì)把提示關(guān)了的。
關(guān)閉 PHP 提示的方法:
打開php.ini:
error_reporting = E_ALL
改為:
error_reporting = E_ALL 改為: error_reporting = E_ALL & ~E_NOTICE
error_reporting = E_ALL & ~E_NOTICE
還有個(gè)不是辦法的辦法就是
在每個(gè)文件頭上加error_reporting(0); //只適用于當(dāng)前頁
<?php error_reporting(0);//加上error_reporting(0);就不會(huì)彈出警告了 $user=$_GET['username']; echo $user; ?>