DataMapper - Using INET_NTOA/INET_ATON? |
[eluser]Basketcasesoftware[/eluser]
wanwizard is the prime candidate for that one. And I can write a function to convert an IP address to an integer and back again quite easily. There are lots of ways to skin this cat.
[eluser]KarlBallard[/eluser]
I've done some research and it turns out that you don't need to do it that way.. Code: $ip_address = $_SERVER['REMOTE_ADDR']; Output on a localhost: Code: Array Google is your friend, use it.
[eluser]sorenchr[/eluser]
Thanks Karl! But that whole deal compared to a single line of code isn't really worth it.
[eluser]sorenchr[/eluser]
[quote author="KarlBallard" date="1297915795"]The bits you require are will be one-liners.. I just put them into an example and dumped the results.. You need to focus on the ip2long and the long2ip functions...[/quote] You are absolutely right, I think I raced through your answer. That'll certainly work and I think I'll use it , thanks again. It would be nice though to find a solution to my initial question.
[eluser]KarlBallard[/eluser]
I'm not familiar with the Datamapper ORM, but surely something like: Code: $u->ip = ip2long($this->input->ip_address());
[eluser]Basketcasesoftware[/eluser]
Yep, it sure would. and Code: $ip_address=long2ip($u->ip); for the reverse.
[eluser]sorenchr[/eluser]
Shameless bumping. My initial question is yet to be answered
[eluser]WanWizard[/eluser]
The answer was already given: Code: // SELECT INET_NTOA(ipaddr) AS ip_address As Datamapper objects are stored using the save() method, you can't use INET_ATON, you need to use one of the suggestions mentioned above and set $object->ipaddr.
[eluser]sorenchr[/eluser]
[quote author="WanWizard" date="1298597481"]The answer was already given: Code: // SELECT INET_NTOA(ipaddr) AS ip_address As Datamapper objects are stored using the save() method, you can't use INET_ATON, you need to use one of the suggestions mentioned above and set $object->ipaddr.[/quote] You are quite right. Thanks for the response. |
Welcome Guest, Not a member yet? Register Sign In |