Welcome Guest, Not a member yet? Register   Sign In
Post Visit CounterWith Ip
#6

(01-17-2021, 03:44 PM)thedragon655 Wrote: does anyone knows how to implement  an IP based view counter when someone clicks my posts? how do we make this in ci4 thank you
the  code needs get user location  use _helper ci4 then call funtion in controller  all you need 
PHP Code:
function getCountryByIp($ip)

    {
        try {
            $xml file_get_contents(
                "http://www.geoplugin.net/json.gp?ip=" $ip);

        } catch (Exception $exception) {
            $xml null;

        }

        if (isset($xml)) {
            $ipdat = @json_decode($xml);
        } else {
            $xml null;
        }




        if ($xml != null and isset($ipdat->geoplugin_countryName)) {
            return array('country' => $ipdat->geoplugin_countryName,
                'code' => $ipdat->geoplugin_currencyCode,
                'city' => $ipdat->geoplugin_city,
                'lat' => $ipdat->geoplugin_latitude,
                'lang' => $ipdat->geoplugin_longitude'flag' => true);
        } else {
            return array('country' => '',
                'code' => '',
                'city' => '',
                'lat' => '',
                'lang' => '''flag' => false);

        }

    
Enlightenment  Is  Freedom
Reply


Messages In This Thread
Post Visit CounterWith Ip - by thedragon655 - 01-17-2021, 03:44 PM
RE: Post Visit CounterWith Ip - by InsiteFX - 01-18-2021, 03:28 AM
RE: Post Visit CounterWith Ip - by AndresHDZ - 01-18-2021, 07:02 AM
RE: Post Visit CounterWith Ip - by thedragon655 - 01-19-2021, 07:29 AM
RE: Post Visit CounterWith Ip - by AndresHDZ - 01-19-2021, 08:30 AM
RE: Post Visit CounterWith Ip - by paliz - 01-19-2021, 12:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB