避免在访问$ _POST,$ _GET和其他变量时在PHP中使用isset? [英] Avoid using isset in PHP when accessing $_POST, $_GET, and other variables?

查看:193
本文介绍了避免在访问$ _POST,$ _GET和其他变量时在PHP中使用isset?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免PHP每次尝试检查变量(如果它有内容并且某个变量尚未使用)时返回未定义的变量错误?在我以前的设置,我可以检查$ _POST ['email'],即使我还没有把任何东西。它只返回一个空白或空结果。这就是我想要我的PHP设置工作,但对我的生活,我似乎不能找出如何配置它。 :(

how can I prevent PHP from returning an Undefined variable error every time I try to check a variable if it has contents and that certain variable hasn't been used yet? In my previous setup, I can check $_POST['email'] even if I haven't put anything into it yet. It simply returns a blank or empty result. That's how I want my PHP setup to work but for the life of me, I can't seem to find figure out how to configure it. :(

示例:

<?php
if ($_POST['info'] != '') {
  // do some stuff
}
?>
<form method="post">
<input type="text" name="info" />
<input type="submit" />
</form>

当您在单个PHP页面中使用上述脚本并在当前设置上运行它时,会返回未定义可变错误在我以前的设置,该脚本工作像一个魅力。任何人都可以分享一些光到这个问题我的,如果你需要更多的细节,只是这样,我会尝试添加更多的细节, 。

When you use the above script in a single PHP page and run it on my current setup, it returns an Undefined variable error. On my previous setup, that script worked like a charm. Can anyone share some light into this problem of mine. If you need further details, just say so and I will try to add more details to this post.

知道有关 isset()检查,但我不想将其用于所有

I know about the isset() checking but I don't want to use it on all of my scripts. I want it to not be that restrictive about variables.

推荐答案

关于变量

Most likely it's not an error, but a Warning. You can set PHP not to display errors/warnings if you want. Just add this to the begining of your code:

很可能它不是一个错误,而是一个警告。你可以设置PHP不显示错误/警告,如果你想要的。只需将它添加到代码的开头:

ini_set('display_errors', 0);

Altough, I recommend you not to be lazy and have your code not display any errors, warnings, notices whatsoever, better safe than sorry.

Altough,我建议你不要懒惰,并且你的代码不会显示任何错误,警告,通知

And the preferred way to do what you want to do is

这篇关于避免在访问$ _POST,$ _GET和其他变量时在PHP中使用isset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆