0

I have been getting this error message displayed as a header on the website and in the site error_log:

[18-Nov-2017 23:06:13 America/New_York] PHP Warning: posix_uname() has been disabled for security reasons in /home/reddirtr/public_html/holland_college_mw19/includes/GlobalFunctions.php on line 1450

How can I change the code in GlobalFunctions.php to remove the warning?

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;

}

Ron K.
  • 123
  • 8

2 Answers2

0

You can use the @ character to hide any error messages generated from that expression:

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

You can use it as follow:

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

Keep in mind that it doesn't fix the problem, it just hides the error message. Also, you can read the chapter "Errors -> Basic" for basic configurations to hide/show error messages in your script.

Progman
  • 16,827
  • 6
  • 33
  • 48
  • The use of the '@' sign as you indicated did the trick and suppressed the error message I was getting. Thank you. How could I change that statement to force the variable $uname to be false? – Ron K. Nov 19 '17 at 14:04
  • @RonK. You can check the result of that statement when the function is blocked. I guess it will be `null` so you can check against it. – Progman Nov 19 '17 at 14:15
0

By default, the server blocks some functions if any suspicious activities occur. So, try editing the php.ini file by adding

disable_functions=

that function sets disable_functions to none. You can add some functions if you need to.

CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
Santosh Reddy
  • 7
  • 1
  • 1
  • 7