How to detect if $_POST is set?(如何检测是否设置了 $_POST?)
问题描述
我想知道如何检测是否设置了 $_POST.
I want to know how to detect if $_POST is set or not.
现在我是这样检测的:
if(isset($_POST['value']))
但我不再关注是否设置了值.基本上,任何 POST 都可以.
But I'm not looking if value is set anymore. Basically, any POST will work.
if(isset($_POST))
我不确定 PHP 是如何处理的.Perhabs isset($_POST) 总是返回 true,因为它是 PHP 全局的?
I'm not sure how PHP handle this. Perhabs isset($_POST) is always returns true since it's a PHP global?
基本上,我该怎么做?
推荐答案
尝试:
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {}
检查您的脚本是否已发布.
to check if your script was POSTed.
如果传递了额外的数据,$_POST 不会为空,否则会.
If additional data was passed, $_POST will not be empty, otherwise it will.
您可以使用 empty 方法来检查它是否包含数据.
You can use empty method to check if it contains data.
if ( !empty($_POST) ) {}
这篇关于如何检测是否设置了 $_POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检测是否设置了 $_POST?
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
