【问题标题】:To make `no-variable` if-clause in PHP在 PHP 中制作 `no-variable` if-clause
【发布时间】:2009-08-14 20:16:57
【问题描述】:

如何使 if -clause which do this and this if

  1. PHP 的 URL 中没有变量?
  2. PHP 的 URL 中没有具有值的变量?

对于 #1 的 if 子句应该为真的 URL 示例:

www.example.com/index.php
example.com/index.php
example.com/index.php?

对于 #2 的 if 子句应该为真的 URL 示例:

example.com/index.php?successful_registration
example.com/index.php?successful_login

以下是我不成功的 if -clause for $1

if (isset($_REQUEST[''])) {
      // do this
}

【问题讨论】:

  • 感谢您的回答! - Lepidosteus 的评论解决了第一个问题。

标签: php url if-statement


【解决方案1】:
if ( 0 == count( $_GET ) )
{
  // do this
}

if ( empty( array_keys( $_GET ) ) )
{
  // do this
}

if ( '' == $_SERVER['QUERY_STRING'] )
{
  // do this
}

【讨论】:

    【解决方案2】:

    您需要检查 $_GET 和 $_SERVER["query_string"]。

    如果查询字符串为空,则您只有基本 url。如果查询字符串不为空,但 $_GET 变量之一为空,则您的域无效。

    【讨论】:

      【解决方案3】:

      If 语句不是循环。不过,您可以将其称为条件。

      if(isset($_REQUEST['successful_registration'])) {
        //do this
      }elseif(isset($_REQUEST['successful_login'])) {
        //do this
      }else{
        //do this
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-05
        • 2013-03-28
        • 2016-11-02
        • 2011-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-07
        相关资源
        最近更新 更多