PHP Notice: undefined index 完美解决方法
来源:互联网 发布:腾讯视频mac 编辑:程序博客网 时间:2024/05/18 02:42
平时用$_GET[‘xx’] 取得参数值时,如果之前不加判断在未传进参数时会出现这样的警告:
PHP Notice: undefined index xxx
虽然可以通过设置错误显示方式来隐藏这个提示,但是这样也有隐患,就是在服务器的日志中会记录这些提示,导致日志文件异常庞大!
下面是引用网上流行的解决方法:
首先,这个不是错误,是warning。所以如果服务器不能改,每个变量使用前应当先定义。
方法1:服务器配置修改
修改php.ini配置文件,error_reporting = E_ALL & ~E_NOTICE方法2:对变量进行初始化,规范书写(比较烦琐,因为有大量的变量)。但还没有找到好定义方法,望大家指教
方法3:每个文件头部加上:error_reporting(0); 如果不行,只有打开php.ini,找到display_errors,设置为display_errors = Off。以后任何错误都不会提示。
方法4 :做判断:isset($_GET[“page”]) if-else判断或者加上’@’表示这行如果有错误或是警告不要輸出
如:@page= _GET[“page”]方法5:file1.php文件把
xx变量付一个值,用post传递给file2.php,如果file2.php没有 xx的定义,而直接使用yy= xx; 系统就会报错:"undifined variaablexx”,如果file2.php的文件开始用 xx="";定义,那么file1.php的$xx值就传不过来了!file2.php里可以这样
if(!isset(xx)) xx=”“;
但Jones认为,这些方法都不太方便。你不妨这样解决:
定义一个函数:
function _get($str){ $val = !<font color="#FF0000">empty</font>($_GET[$str]) ? $_GET[$str] : null; return $val;}然后在用的时候,直接用 _get(‘str’) 代替 $_GET[‘str’] 就行啦~
是不是很方便?
- PHP Notice: undefined index 完美解决方法
- PHP Notice: undefined index 完美解决方法
- PHP Notice: undefined index 完美解决方法
- PHP Notice: undefined index 完美解决方法
- PHP Notice: undefined index 完美解决方法
- PHP Notice: undefined index 解决方法
- PHP Notice: Undefined index: ... 问题的解决方法
- php 中 Notice:undefined index 解决方法
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index: ... 问题的解决方法:
- php提示Notice: Undefined index解决方法
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index:
- PHP Notice: Undefined index和Undefined variable问题的解决方法:
- Notice: Undefined index: 提示解决方法
- php出现 Notice: Undefined index: name 的解决方法
- php 解决Notice: Undefined index:
- [DFS]poj 1321 棋盘问题
- 一维数组的逆序输出
- 排序算法总结
- 2017 年 1 月,人工智能取代了 34 名人类员工
- Java.lang.Class
- PHP Notice: undefined index 完美解决方法
- 高等数学-《函数与极限》总结笔记
- 我的向往
- Awesome
- 题解:Find Largest Value in Each Tree Rowt
- Poj3259(floyd)
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- 高等数学-对函数极限的理解
- 《设计模式》-- 策略模式