Discuz X2运行在PHP5.2.17下,php-5.2.17_errors.log出现大量的错误提示:

PHP Notice: Undefined index: fromuser in E:\bbs\index.php on line 122

这个错误提示大概意思是:存在未定义的变量。

虽然这个报错不影响程序运行,但错误日志每天不断增加也很烦人。怎么解决呢?

Discuz出现Undefined index错误解决方法

打开discuz的首页文件 index.php

查找120行及122行:

if(!empty($url)) {
    $delimiter = strrpos($url, '?') ? '&' : '?';
    if($_GET['fromuid']) {
        $url .= $delimiter.'fromuid='.$_GET['fromuid'];
    } elseif($_GET['fromuser']) {
        $url .= $delimiter.'fromuser='.$_GET['fromuser'];
    }
    header("HTTP/1.1 301 Moved Permanently");
    header("location: $url");
} else {
    require './'.$_ENV['curapp'].'.php';
}

修改为:

if(!empty($url)) {
    $delimiter = strrpos($url, '?') ? '&' : '?';
    if(isset($_GET['fromuid']) && $_GET['fromuid']) {
        $url .= $delimiter.'fromuid='.$_GET['fromuid'];
    } elseif(isset($_GET['fromuser']) && $_GET['fromuser']) {
        $url .= $delimiter.'fromuser='.$_GET['fromuser'];
    }
    header("HTTP/1.1 301 Moved Permanently");
    header("location: $url");
} else {
    require './'.$_ENV['curapp'].'.php';
}

通过增加 isset 函数来判断变量是否设置。

标签: php, 函数, discuz

添加新评论