Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Playing with PHP API, data type issue ?

Featured Replies

  • Newbies

Hello everyone.

 

I'm plyaing for the first time with filemaker PHP API, and, even if I succeed on doing a basic newFindRequest (), I'm stuck on something that must be very simple but I can't get working.

 

 

I have a layout called "Php Ipv4 Blocks" linked to a table that keep tracks of IPs as long and the country associated to thoses IPs. My table structure looks like this :

   

id                         :  unique id   (number)

country_id           :  id of a country   (number)

integer_ip_from   :  starting value of ip range as long   (number)

integer_ip_from   :  ending value of ip range as long   (number)

 

 

In my php script, I transform an ip to a long value and then, I try to perform a newFindRequest() where 

integer_ip_from <= ip as long

integer_ip_to     >= ip as long

 

 

I use this function to transfor IP to long :

$longIp  =  printf("%un", ip2long($IP));

If I try with a random ip, for exemple : 173.176.47.188

Converted as long I find this value :    2914004924

 

So now, I try to perform my find :

function getCountryForIp ($IP){ 
$longIp  =  printf("%un", ip2long($IP));


$findCommand = $GLOBALS["fm"]->newFindCommand("Php Ipv4 Blocks");
$findCommand->addFindCriterion("integer_ip_from", '<=' . $longIp);
$findCommand->addFindCriterion("integer_ip_to"  , '>=' . $longIp);


$result   = $findCommand->execute();


if (FileMaker::isError($result))
{
echo $result->getCode();
echo $result->getMessage();
echo "No country found";
return false;
}
else
{
$record  = $result->getFirstRecord();
$country = $record->getField("country_id");
echo "country id " . $country;
return true;
}

This will return me : 401 No records match the request.

 

 

Note that if for testing purpose I replace my var $longIp and input the long value directly I find my record:

$longIp  =  2914004924; //printf("%un", ip2long($IP));

Can you guys help me on this issue ?

Thanks.

I believe you should store the field for searching as FileMaker Number type( the output of ip2long() ) without the linebreak.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.