lukeyouell / craft-geocookie Goto Github PK
View Code? Open in Web Editor NEWCollect information about a visitor's location based on their IP address and store the information as a cookie.
License: MIT License
Collect information about a visitor's location based on their IP address and store the information as a cookie.
License: MIT License
Secret API key is not included in request when using ipapi.co, leading to an error being returned when quota is met
ipapi.co returns location information correctly:
{
"ip": "123.123.123.0",
"city": "City, etc.",
}
ipapi.co returns error code:
{
"error": true,
"statusCode": 429
}
In Geo Cookie plugin settings, set:
Including the API key in services/GeoService.php resolves the issue:
case 'ipapi':
$clientUrl = 'https://ipapi.co';
// $clientPath = $ipAddress.'/json';
$clientPath = $ipAddress.'/json/?key='.$settings->apiKey;
Hi @lukeyouell Thanks for writing the Geo Cookie plugin, it works great. Quick question/note: I saw that the DB table gets filled with entries although Logging is disabled in the CP. The entries are not visible in the Utilities section though but they do appear in the DB. Is there any way to completely disable the Logging functionality (also in DB)?
I just upgrade to version 1.3.2 and it looks like these migrations didn't run:
I think we might be hitting our max daily API limit for ipapi.co, but since there is no logging, I can't know for sure without hacking the plugin directly on production. It would be really useful to log when there is some sort of error retrieving the location.
If you don't think you have time to add this anytime soon, let me know, and I can submit a PR.
Using ipapi:
{
"error": true, "errorMessage": "cURL error 3: IPv6 numerical address used in URL without brackets (see http:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html)"
}
We've used this on a large prod site which was built two years ago (but has been updated regularly to latest craft versions). We've now seen the no longer maintained alert. How long do you think we can get away with using this before finding an alternative?
The plugin works great! But when working locally i get the following error
Neither the property "country" nor one of the methods "country()", "getcountry()"/"iscountry()"/"hascountry()" or "__call()" exist and have public access in class "stdClass".
full stack trace here
Twig_Error_Runtime: Neither the property "country" nor one of the methods "country()", "getcountry()"/"iscountry()"/"hascountry()" or "__call()" exist and have public access in class "stdClass". in /Users/design5/Documents/Websites/telarc/templates/_structure/_site.html:65
Stack trace:
#0 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/helpers/Template.php(73): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig_Source), Object(stdClass), 'country', Array, 'any', false, false)
#1 /Users/design5/Documents/Websites/telarc/storage/runtime/compiled_templates/79/79ca6133bc3596c9e821bc5bfe5bdb0ad6a5c722004c15ce05d2743815eb07a6.php(100): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig_Source), Object(stdClass), 'country', Array)
#2 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(189): __TwigTemplate_f94a4377a8b34adfe4d749baf923c73317a551491ca863f14e78b34978f553f0->block_body(Array, Array)
#3 /Users/design5/Documents/Websites/telarc/storage/runtime/compiled_templates/41/416fbd7f9011d33c0f7ed2151c9d92c1b6184eca65467556117182805169c4df.php(189): Twig_Template->displayBlock('body', Array, Array)
#4 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(390): __TwigTemplate_b27d31bed5938ee2a9579ae09454ec63fb71fac2144b45bd7e20e2d9b934ab04->doDisplay(Array, Array)
#5 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#6 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#7 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#8 /Users/design5/Documents/Websites/telarc/storage/runtime/compiled_templates/79/79ca6133bc3596c9e821bc5bfe5bdb0ad6a5c722004c15ce05d2743815eb07a6.php(29): craft\web\twig\Template->display(Array, Array)
#9 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(390): __TwigTemplate_f94a4377a8b34adfe4d749baf923c73317a551491ca863f14e78b34978f553f0->doDisplay(Array, Array)
#10 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#11 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#12 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#13 /Users/design5/Documents/Websites/telarc/storage/runtime/compiled_templates/70/7027c84fe1d306f7f67c040c1632cceb1ac7f0cf8f8d6143e926a2488ca474c9.php(28): craft\web\twig\Template->display(Array, Array)
#14 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(390): __TwigTemplate_4cdb4a815d96e1c196a6d23cb266ccfe8e7346e0289bc5937baaf9618fd25dbc->doDisplay(Array, Array)
#15 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#16 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#17 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#18 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Template.php(375): craft\web\twig\Template->display(Array)
#19 /Users/design5/Documents/Websites/telarc/vendor/twig/twig/lib/Twig/Environment.php(289): Twig_Template->render(Array)
#20 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/View.php(305): Twig_Environment->render('', Array)
#21 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/View.php(352): craft\web\View->renderTemplate('', Array)
#22 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/Controller.php(128): craft\web\View->renderPageTemplate('', Array)
#23 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/controllers/TemplatesController.php(78): craft\web\Controller->renderTemplate('', Array)
#24 [internal function]: craft\controllers\TemplatesController->actionRender('', Array)
#25 /Users/design5/Documents/Websites/telarc/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#26 /Users/design5/Documents/Websites/telarc/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#27 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/Controller.php(76): yii\base\Controller->runAction('render', Array)
#28 /Users/design5/Documents/Websites/telarc/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#29 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('templates/rende...', Array)
#30 /Users/design5/Documents/Websites/telarc/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#31 /Users/design5/Documents/Websites/telarc/vendor/craftcms/cms/src/web/Application.php(263): yii\web\Application->handleRequest(Object(craft\web\Request))
#32 /Users/design5/Documents/Websites/telarc/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#33 /Users/design5/Documents/Websites/telarc/public_html/index.php(22): yii\base\Application->run()
#34 {main}
So my issue is that I get the server location instead of the client.
My setup is using Cloudfront on a Ec2 server in Amazon where Craft CMS is installed.
Basically what I believe that is happening is that the request to craft comes from Cloudfront and not from the client, so then I receive the incorrect location.
Not sure how the plugin detects the viewer location. It looks like there is some header available on Cloudfront regarding the viewer country:
CloudFront-Viewer-Country
Craft - Craft Pro 3.0.15
Geo Cookie - 1.2.1
Is there any way to use this in a local development mode where it doesn't consistently fail trying to lookup 127.0.0.1? ๐ค
I didn't see MaxMind in the supported APIs list.
Can it be supported, or is there a reason for it to be excluded?
Getting this error a after doing a Craft 3 Update (Updated to V3.1.26)
lukeyouell\geocookie\services\GeoService::location(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "stdClass" of the object you are trying to operate on was loaded before unserialize() gets called or provide an autoloader to load the class definition
Attached is the full error page I get.
We are using this plugin and ipapi.co with a paid plan. Somewhat recently, we've been getting cURL timeout errors, but only when using ipapi.co as the API Source.
cURL error 28: Connection timed out after 5073 milliseconds (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
If I switch to a different API source, things work fine. I was going to maybe contact ipapi.co directly, but their API status shows no issues, and I can curl it directly from the command line and it works fine.
Any thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.