【问题标题】:posix_uname() has been disabled for security reasonsposix_uname() 出于安全原因已被禁用
【发布时间】:2017-11-19 05:17:06
【问题描述】:

我在网站上和网站 error_log 中看到此错误消息显示为标题:

[2017 年 11 月 18 日 23:06:13 America/New_York] PHP 警告:出于安全原因,posix_uname() 已在 /home/reddirtr/public_html/holland_college_mw19/includes/GlobalFunctions.php 第 1450 行禁用

如何更改 GlobalFunctions.php 中的代码以消除警告?

function wfHostname() {
static $host;
if ( is_null( $host ) ) {

    # Hostname overriding
    global $wgOverrideHostname;
    if ( $wgOverrideHostname !== false ) {
        # Set static and skip any detection
        $host = $wgOverrideHostname;
        return $host;
    }

    if ( function_exists( 'posix_uname' ) ) {
        // This function not present on Windows
        $uname = posix_uname();
    } else {
        $uname = false;
    }
    if ( is_array( $uname ) && isset( $uname['nodename'] ) ) {
        $host = $uname['nodename'];
    } elseif ( getenv( 'COMPUTERNAME' ) ) {
        # Windows computer name
        $host = getenv( 'COMPUTERNAME' );
    } else {
        # This may be a virtual server.
        $host = $_SERVER['SERVER_NAME'];
    }
}
return $host;

}

【问题讨论】:

    标签: php wikimedia


    【解决方案1】:

    您可以使用@ 字符来隐藏从该表达式生成的任何错误消息:

    PHP 支持一种错误控制运算符:at 符号 (@)。当附加到 PHP 中的表达式时,该表达式可能生成的任何错误消息都将被忽略。

    您可以按如下方式使用它:

    if ( function_exists( 'posix_uname' ) ) {
        // This function not present on Windows
        $uname = @posix_uname();
    } else {
        $uname = false;
    }
    

    请记住,它并不能解决问题,它只是隐藏了错误消息。此外,您可以阅读章节"Errors -> Basic" 了解在脚本中隐藏/显示错误消息的基本配置。

    【讨论】:

    • 按照您的指示使用“@”符号可以解决问题并抑制我收到的错误消息。谢谢你。我如何更改该语句以强制变量 $uname 为假?
    • @RonK。当函数被阻塞时,您可以检查该语句的结果。我猜它会是null,所以你可以检查一下。
    【解决方案2】:

    默认情况下,如果发生任何可疑活动,服务器会阻止某些功能。因此,尝试通过添加来编辑php.ini 文件

    disable_functions=
    

    该函数将disable_functions 设置为无。如果需要,您可以添加一些功能。

    【讨论】:

      猜你喜欢
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2015-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2016-02-07
      相关资源
      最近更新 更多