How can I detect if the user is on localhost in PH

2019-01-21 03:23发布

In other words, how can I tell if the person using my web application is on the server it resides on? If I remember correctly, PHPMyAdmin does something like this for security reasons.

8条回答
孤傲高冷的网名
2楼-- · 2019-01-21 03:47

Newer OS users (Win 7, 8) may also find it necessary to include an IPV6-format remote address in their whitelist array:

$whitelist = array('127.0.0.1', "::1");

if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
    // not valid
}
查看更多
在下西门庆
3楼-- · 2019-01-21 03:51

As a complement, as a function...

function isLocalhost($whitelist = ['127.0.0.1', '::1']) {
    return in_array($_SERVER['REMOTE_ADDR'], $whitelist);
}
查看更多
登录 后发表回答