• Payment Plugins Poll

    We need your feedback on the need for updated payment plugins. Please go here and give us your feedback.

  • Joomla 5.1

    For running J!5.1 you must install Fabrik 4.1
    See also Announcements

  • Subscription and download (Fabrik 4.1 for J!4.2+ and J!5.1) are working now

    See Announcement
    Please post subscription questions and issues here

    We have resolved the issue with the J! updater and this will be fixed in the next release.

Solved Get country by IP using API

dimoss

Well-Known Member
Hi all,

Searching older posts I found the following thread which seems to be an approach to get the country using an API having the user IP.
https://fabrikar.com/forums/index.php?threads/get-country.49532/#post-259049

I applied it creating a form using a calc element with the following code using the free API from https://ip-api.com/

PHP:
$ip = '{fab_ratings___ip}';
$api_url = 'http://ip-api.com/json/'.urlencode($ip);
//var_dump($api_url);exit;
$hostinfo = file_get_contents($api_url);
//var_dump($hostinfo);exit;
$hostinfo = json_decode($hostinfo);
return $hostinfo->country;

Now the funny part comes. As long as i remove the comment from 'var_dump($hostinfo)' the script gives exits with the correct info and the correct country which in my case is Greece. If I comment 'var_dump($hostinfo)' the script records a wrong country which is always Finland regardless if I use or not use a VPN! Same it happens for others which i gave the same form URL to try.

In all cases the $api_url is correct.

I have no clue why this is happening.
 
Well. I don't know why but the issue was in
PHP:
$ip = '{fab_ratings___ip}';

Strangely it works only if I append '_raw' so the following seems the solution.
PHP:
$ip = '{fab_ratings___ip_raw}';
 
Back
Top