Question

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

Was it helpful?

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);

OTHER TIPS

The format for this has recently been changed. If you can pull down the newest code (make sure to backup and restore your ion_auth.php config file).

Then change your users.ip_address database field to a varchar(15).

Now IP's will be stored as strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top