简体   繁体   English

我如何设置我的PHP以输入用户IP

[英]How do i set my php to input users IP

Could someone help me please? 有人可以帮我吗?

Im trying to make it so that when a user logs on , it checks if there is anything in the IP part for that user in cPanel, and if its empty then update it with their IP, but if it isnt empty then do nothing. 我试图这样做,以便当用户登录时,它会检查cPanel中该用户的IP部分中是否有任何内容,如果为空则使用其IP更新它,但是如果不为空,则不执行任何操作。

I tried doing 我试着做

if(empty($row['IP']))
{
//set ip
}

But for some reason i cant get the set ip to work. 但是由于某种原因,我无法使设置的IP工作。

for getting the client IP by this code: 通过此代码获取客户端IP:

$theClientIp = $_SERVER['REMOTE_HOST'];

then you can make it session like this: 那么您可以像这样进行会话:

session_start();
$_SESSION['ip']=$theClientIp;

everywhere you can get the ip value by echoing this 到处都可以通过回显此值获得ip值

session_start(); $_SESSION[ip'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM