Search code examples
phpip-addression-auth

Ion_Auth format for ip address


For user login I use Ion_Auth plugin for code igniter. This library stores IP addresses of users in a mysql VARBINARY field.

For a 90.46.67.92 IP address, I can see the data in database like this :

  • "5A2E435C" accessing with a small database managing library (adminer)
  • "Z.C\" accessing with Phpmyadmin

To access this field in my app I use Code Igniter Active Record lib. I saw on SO topics about packing IP address with inet_pton and unpacking with inet_ntop. With the IP address above, inet_ntop gives me a failure due to bad format.

Any idea to :

  1. Discover format of returned field with Active Record library ? (binary / hex / utf8..)
  2. Un pack this returned field ?

PS : I use PHP 5.2


Solution

  • THe IP address 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);