⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Storing and searching IP address as long in database.



milamber
  • profile picture
  • Member

Posted 28 October 2012 - 20:27 PM

Hello,

I have managed to quickly create small table where one field is IP address. As the better way to store Ip is int(11) then I have tried to use GroceryCrud this way.

What I have done is:



$crud = new grocery_CRUD();
$crud->set_table('tickety');
$crud->field_type('ip', 'string');
$crud->callback_before_insert(array($this,'change_ip_insert_callback'));
$crud->callback_before_update(array($this,'change_ip_update_callback'));
$crud->callback_column('ip',array($this,'change_ip_show_callback'));

$output = $crud->render();
$this->_example_output($output);



It works this way and uses some php functions like:


function __convertIpToString($ip)
{
$long = 4294967295 - ($ip - 1);
return long2ip(-$long);
}
function __convertIpToLong($ip)
{
return sprintf("%u", ip2long($ip));
}


However how to teach CodeIgniter to use such convertion also when doing "search" function? Like before search on IP collumn please do convertIPToString and then compare.

Also since the field is limited to int(11) GroceryCrud limits the size of this field how I can change the char limit on it?

Thank you very much for your help in advance!

milamber
  • profile picture
  • Member

Posted 02 November 2012 - 08:13 AM

BUMP...

Not anyone was trying to deal with IP addresses?