PHP Notice: undefined index xxx
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 variaable $xx”, 如果file2.php的文件开始用$xx=”";定义,那么file1.php的$xx值就传不过来了!
file2.php里可以这样
if(!isset($xx)) $xx=”";
但Jones认为,这些方法都不太方便。你不妨这样解决:
定义一个函数:
查看源代码
打印帮助
1 |
function _get( $str ){ |
2 |
$val = ! empty ( $_GET [ $str ]) ? $_GET [ $str ] : null; |
3 |
return $val ; |
4 |
} |
然后在用的时候,直接用 _get(’str’) 代替 $_GET['str'] 就行啦~
http://duanchunlingshu.blog.163.com/blog/static/1050941652010718111751666/(原始出处)
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
; E_ALL - All errors and warnings (doesn't include E_STRICT)
所有错误和警告(除开E_STRICT)
; E_ERROR - fatal run-time errors (在运行中致命的错误)
; E_RECOVERABLE_ERROR - almost fatal run-time errors(运行中几乎致命的错误)
; E_WARNING - run-time warnings (non-fatal errors)运行中出现的警告(非致命错误)
; E_PARSE - compile-time parse errors 编译时语法错误
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string) 运行时通知(这些警告,这通常会结果
在你;从一个错误代码,但它是可能的,它是
;故意(例如使用未初始化的变量和
依托这一事实,它会被自动初始化为一个
空字符串);
; E_STRICT - run-time notices, enable to have PHP suggest changes; to your code which will ensure the best interoperability 运行时的告示,使有PHP建议更改你的代码将确保最佳的互操作性和论述了前向兼容与你的代码
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup 致命错误,发生在PHP的初始启动
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup 警告(非致命性错误),发生在PHP的
初始启动;
; E_COMPILE_ERROR - fatal compile-time errors 编译时致命的错误
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) 编译时警告(非致命错误)
; E_USER_ERROR - user-generated error message 自创内容错误信息
; E_USER_WARNING - user-generated warning message 自创内容警告信息
; E_USER_NOTICE - user-generated notice message 自创内容通知消息
转载于:https://blog.51cto.com/yang12313/568528
PHP Notice: undefined index xxx相关推荐
- PHP Notice: undefined index 解决方法
平时用$_GET['xx'] 取得参数值时,如果之前不加判断在未传进参数时会出现这样的警告: PHP Notice: undefined index xxx 虽然可以通过设置错误显示方式来隐藏这个提示 ...
- ie下面出现Notice: Undefined index: HTTP_REFERER 的解决办法
为什么80%的码农都做不了架构师?>>> 一:问题出现 发现这一问题是在一次开发当中做了一个跳转在FF下面能正常跳转,最后将项目传到线上之后,测试的却告诉我在IE下面不能跳转, ...
- PHP出现 Notice: Undefined index:...的原因及解决办法
<?php$user=$_GET['username']; echo $user; ?> 直接运行改php脚本的话会出现" Notice: Undefined index: us ...
- PHP问题 —— Notice: Undefined index:
1.1 Notice: Undefined index: login in 1.1.1 现象 访问网页,出现如下错误信息: ( ! ) Notice: Undefined index: login ...
- ***PHP Notice: Undefined index: ..问题的解决方法
***PHP Notice: Undefined index: ..问题的解决方法 参考文章: (1)***PHP Notice: Undefined index: ..问题的解决方法 (2)http ...
- Notice: Undefined index: 提示解决方法
Notice: Undefined index:出现这个信息的意思你使用了未定义的变量.这个不是错误,是一个提示,并不会影响代码的执行. 解决方法: 方法1:修改php.ini配置文件,error_r ...
- php中的 notice,PHP中出现Notice: Undefined index的三种解决办法
前一段做的一个PHP程序在服务器运行正常,被别人拿到本机测试的时候总是出现"Notice: Undefined index:"这样的警告,这只是一个因为PHP版本不同而产生的警告( ...
- php提示Notice: Undefined index解决方法
php提示Notice: Undefined index解决方法 php提示Notice: Undefined index问题,Undefined index:是指你的代码里存在:"变量还未 ...
- 运行PHP程序时提示“Notice: Undefined index”的解决办法
最近在调试网站程序的时候,不知道怎么经常出现"Notice:Undefined index"的提示,程序又可以正常运行,就是看到这个提示感觉有点不爽,把模板搞乱了,经查其实这个不是 ...
最新文章
- 如何使用 OpenStack CLI - 每天5分钟玩转 OpenStack(22)
- 【BZOJ】1572: [Usaco2009 Open]工作安排Job
- 返回空的List集合
- Python学习预备
- LNMP环境添加第三方模块
- Web安全之权限攻击
- group by 用法解析_GRE数学专项练习及解析概率
- 如何高效判断java数组是否包含某个值
- 程序员修炼境界:心如止水还是心绪不定
- 【图像隐写】基于matlab GUI DWT+SVD数字水印【含Matlab源码 606期】
- Hibernate2 参考文档
- 安装和卸载office以及激活电脑系统血淋淋的教训
- SQL2005到2008数据库升级
- Microsoft OneNote - 图片文字提取
- Hue 集成Hive
- Unity3D之关于动画延时问题
- 迅雷百度网盘不能下载资源 办法总比困难多
- 华为云CDN为什么这么受用户的信赖?
- 豆瓣电影flask网页
- 武大50名学生造卫星,南航“00后”学生造火箭,后浪制造未来可期
热门文章
- memcached mysql 性能测试_InnoDB memcached插件 vs 原生memcached对比性能测试
- python迭代计算pi_python使用三角迭代计算圆周率PI的方法
- 稳压电源的设计与制作_直流稳压电源设计
- python异常处理_Python爬虫入门(5):URLError异常处理
- docker创建mysql实例_使用docker创建mysql实例
- 英特尔核显自定义分辨率_核显也能60帧玩3A大作?原理很简单!8寸电脑掌机游戏测评...
- vue 中indexof_前端小知识-Vue中使用indexOf() 方法
- 汇编学习--6.13--基础知识
- 操作系统面试基本概念
- 【equals与==比较】String的两种拼接