Forums

Can't get ip2long function to work

chriso0258 18 Feb, 2016
Hello,

I'm having trouble getting the php function ip2long() to work. I'm playing around with this function to see how it works. My code is:
<?php
foreach($form->data[vicondb] as $video_net_key) 
{
    if ($video_net_key['ipaddress'] != null)
    {
        echo "The IP address is " . $video_net_key['ipaddress'];
        $iplong = ip2long($video_net_key['ipaddress']);
        echo " --- The ip long conversion is " . $iplong . "<br>";
    }

} // End foreach($form->data[vicondb] as $video_net_key)

echo "End of both foreach statements<br>";
?>

The output looks like this:

    The IP address is 172.26.0.10 --- The ip long conversion is
    The IP address is 172.26.0.31 --- The ip long conversion is
    The IP address is 172.26.0.32 --- The ip long conversion is
    The IP address is 172.26.0.33 --- The ip long conversion is

The ip addresses are stored as varchar types in the table. If I put in the ip address of 172.26.0.33 in an online ip2long converter, I get 2887385121.

I tried this code to see what the variables are:
var_dump($video_net_key['ipaddress']); var_dump($iplong);
and it shows all the correct ip addresses but all the iplong variables are 0 (zero).

I was wondering if you had any ideas or if for some reason Chronoforms was not allowing the ip2long function to function for some reason.

Thanks for any assistance.
Chris.
chriso0258 18 Feb, 2016
Answer
I found the problem. Evidently I have a trailing space after the ip. When I used the trim function it worked.
This topic is locked and no more replies can be posted.