[英]How do I write a function that tells me that I am currently looking at the homepage (/index.php)?
[英]I am looking for a php function that will prevent this: Undefined index: message in
if(defined($_POST["message"]) && defined($_POST["name"]))
{
在这种情况下,不断地抛出异常。 我正在寻找一个可以通过测试后变量是否存在来防止这种情况的函数。如果不存在,则返回false而不是抛出异常
if (isset($_POST["message"]) && isset($_POST["name"])) {
// ....
}
或者,如果您想检查它们是否设置为非空,也可以设置为非空:
if (!empty($_POST["message"]) && !empty($_POST["name"])) {
// ....
}
使用isset
,而不是defined
。
if(isset($_POST["message"]) && isset($_POST["name"])) {
[...]
defined
将字符串作为参数,用于检查常量是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.