[英]How to retrieve visitor ip address in laravel 5.1
I am trying to get site visitors ip address & want to store that in table. 我试图获取网站访问者的IP地址,并希望将其存储在表中。 This is my code to store data 这是我存储数据的代码
public function store(Request $request)
{
$secretcode=str_random(10);
while(1)
{
$txnid=substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$txnstatus=Ticket::where('transactionid',$txnid)->get();
if($txnstatus->isEmpty())
break;
}
$request['ipaddress']=$request->ip();
$request['transactionid']=$txnid;
$request['secretcode']=$secretcode;
$input=$request->all();
Ticket::create($input);
return view('payment');
}
I am using this line to get ip address 我正在使用此行获取IP地址
$request['ipaddress']=$request->ip();
When this code inserts data into database table, it shows like this 当此代码将数据插入数据库表时,它会显示如下
Someone please help me to get this work done. 有人请帮我完成这项工作。 I also used Request::ip() but even that didn't work. 我也使用Request :: ip(),但即使这样也行不通。
Important is that I am working in localhost environment with active internet connection. 重要的是我在具有活动互联网连接的localhost环境中工作。
Your code is working fine. 你的代码工作正常。 $request->ip()
it should work and i tried it by myself to make sure your code is correct. $request->ip()
它应该工作,我自己尝试,以确保您的代码是正确的。 ::1
this result is normal if you run in local environment. ::1
如果您在本地环境中运行,此结果是正常的。 try it in hosting server to see your actual IP 尝试在托管服务器中查看您的实际IP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.