且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

避免在 PHP 中访问 $_POST、$_GET 和其他变量时使用 isset?

更新时间:2023-08-23 13:29:28

很可能不是错误,而是警告.如果需要,您可以将 PHP 设置为不显示错误/警告.只需将其添加到代码的开头即可:

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:

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.

做你想做的事情的首选方式是

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

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