I am trying to get site visitors ip address & want to store that in table. 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
$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.
Important is that I am working in localhost environment with active internet connection.
Your code is working fine. $request->ip()
it should work and i tried it by myself to make sure your code is correct. ::1
this result is normal if you run in local environment. try it in hosting server to see your actual IP
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.