I know we can use the user method of ion auth to get user data.
$user = $this->ion_auth->user()->row();
echo $user->ip_address;
But this gives an output u�8/ .How can I retrieve the actual ip address like 127.0.0.1.
UPDATE
Just to help others.
With help from h2ooooooo,I found that ipaddress is passed through bin2hex(inet_pton($ip))
and then saved in db. To retrieve it use
$user = $this->ion_auth->user()->row();
echo inet_ntop($user->ip_address);
Are you sure that the IP is stored using
inet_pton
?This is the result if we simply convert every 2 characters into decimal:
DEMO
Is that your correct IP?
If it is
inet_pton
(which doesn't make sense as most of those are characters outside regular ASCII scopes) then you can simply useinet_ntop
to get it back.To convert an IP into this hex format, you can do the following:
DEMO