如何检测用户是否在PHP的localhost上? [英] How can I detect if the user is on localhost in PHP?

查看:63
本文介绍了如何检测用户是否在PHP的localhost上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

换句话说,我该如何判断使用我的Web应用程序的人是否在其驻留的服务器上?如果我没记错的话,出于安全考虑,PHPMyAdmin会执行类似的操作.

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.

推荐答案

您还可以使用$_SERVER['REMOTE_ADDR'],Web服务器为其提供客户端请求的IP地址.

You can also use $_SERVER['REMOTE_ADDR'] for which IP address of the client requesting is given by the web server.

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

if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
    // not valid
}

这篇关于如何检测用户是否在PHP的localhost上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆