如何在wordpress中获取作者帖子的IP地址

时间:2017-03-08 22:52:28

标签: php wordpress

我已经在我的wordpress网站上安装了iThemes安全插件,以保护我的网站。另外,我已经安装了 WP Statistics ,以便查看访问者的IP地址。但是,此插件不会记录创建帖子的作者的IP地址。我一直在网上搜索PHP脚本或SQL查询来获取所述IP地址。

有人知道如何使用PHP脚本或SQL查询获取作者的IP地址吗?

1 个答案:

答案 0 :(得分:0)

function get_client_ip() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

这会有所帮助,您只需要将其插入到发布脚本中,然后将其按照普通变量推送到基础。