{"id":21497832,"url":"https://github.com/johnsnook/yii2-visitors","last_synced_at":"2025-07-15T20:30:40.580Z","repository":{"id":57000998,"uuid":"138110543","full_name":"johnsnook/yii2-visitors","owner":"johnsnook","description":"This extension gets the visitor information associated with their ip address, including proxy and geographical information and logs the access and checks if it's blacklisted or whitelisted and takes appropriate action.","archived":false,"fork":false,"pushed_at":"2019-11-24T03:25:49.000Z","size":6498,"stargazers_count":7,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-07T01:18:42.960Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://snooky.biz/projects/visitor","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnsnook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-21T02:41:54.000Z","updated_at":"2023-08-05T14:37:21.000Z","dependencies_parsed_at":"2022-08-21T13:20:51.475Z","dependency_job_id":null,"html_url":"https://github.com/johnsnook/yii2-visitors","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsnook%2Fyii2-visitors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsnook%2Fyii2-visitors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsnook%2Fyii2-visitors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsnook%2Fyii2-visitors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnsnook","download_url":"https://codeload.github.com/johnsnook/yii2-visitors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226066519,"owners_count":17568414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T16:26:54.092Z","updated_at":"2024-11-23T16:26:54.672Z","avatar_url":"https://github.com/johnsnook.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://user-images.githubusercontent.com/4065107/44600120-55c23200-a7a6-11e8-9e2a-1f950cbf949b.jpg)\nYii2 - Visitors\n=====================\n\nThis extension is a half security, half SEO (search engine optimization) tool for webmasters to determing\n\nIt tracks the visitor information associated with the visitor ip address and user agent (browser/OS) info, retrieves  proxy and \"IP info\", including ISP geographical information,  logs the access and checks against rules for  blacklisting or whitelisting, taking appropriate action.\n\nIncludes tools for viewing, searching, filtering and graphically (Including GIS!) exploring your websites visitors.\n\nInstallation\n------------\n\n### 1. Download\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```bash\nphp composer.phar require --prefer-dist johnsnook/yii2-visitors \"*\"\n```\n\nor add\n\n```\n\"johnsnook/yii2-visitors\": \"*\"\n```\n\nto the require section of your `composer.json` file.\n\n### 2. Configure\n\n\nOnce the extension is installed, add 'visitor' to the bootstrap section of your configuration file  :\n\n```php\n    'bootstrap' =\u003e [\n        'log',\n        'visitor',\n    ],\n```\n\nThen add the bare-minimum module definition\n```php\n    'modules' =\u003e [\n        ...\n        'visitor' =\u003e [\n            'class' =\u003e 'johnsnook\\visitor\\Module',\n        ],\n        ...\n    ],\n```\n\nThe routes are defined in the Module file as $urlRules.  These can also be redefined in the module definition.  By default, they look like this for prettyUrls:\n```php\n    'visitor' =\u003e '/visitor/visitor/index',\n    'visitor/index' =\u003e '/visitor/visitor/index',\n    'visitor/blowoff' =\u003e '/visitor/visitor/blowoff',\n    'visitor/\u003cid\u003e' =\u003e 'visitor/visitor/view',\n    'visitor/update/\u003cid\u003e' =\u003e 'visitor/visitor/update',\n```\n\n### 3. Update database schema\n\nThe last thing you need to do is updating your database schema by applying the\nmigrations. Make sure that you have properly configured `db` application component\nand run the following command:\n\n```bash\n$ php yii migrate/up --migrationPath=@vendor/johnsnook/yii2-visitor/migrations\n```\n\nFree API Keys\n-----\n1) For the map to render in Visitor view, you must have a MapQuest key.  Go to https://developer.mapquest.com/plan_purchase/steps/business_edition/business_edition_free/register for a free API key.\nIf you don't have this set, the map won't display.\n\n2) Ipinfo.io limits the number of requests each day to 100 but with a key you can make 1000 a day.  Go to https://ipinfo.io/signup for a free API key\nIf you don't have this set, you'll be limited to 100 requests per day.\n\n3) Proxycheck.io limits the number of requests each day to 100 but with a key you can make 1000 a day.  Go to https://proxycheck.io/ for a free API key\nIf you don't have this set, you'll be limited to 100 requests per day.\n\n4) Whatismybrowser.com is serious business, so having an API is mandatory to use their service.  Go to https://developers.whatismybrowser.com/api/signup/basic for a free API key, but be prepared to provide an \"app name\" and website.\nIf you don't have this set, no data beyond the basic USER_AGENT string will be captured.\n\nCustomization\n-----\nSo, you should be able to go to  ```http://yoursit.biz/index.php?r=visitor/visitor/index``` or, if you have prettyUrl enabled, ```http://yoursite.com/visitor``` and see the visitor index.\n\nBut you'll probably want to make your own views.  If it was me, I'd copy the controller and views to your backend or basic controllers \u0026 views directories.  But maybe there's some best practices way to do it.\n\nI have left the layout empty so that the pages should be rendered with your layouts/theme.\n\nWhen you're done getting all your keys, and deciding that there are some controller actions you're not interested in tracking, your module configuration might look something like this:\n```php\n    'modules' =\u003e [\n        ...\n        'visitor' =\u003e [\n            'class' =\u003e 'johnsnook\\visitor\\Module',\n            'ipInfoKey' =\u003e 'Not a real key, obviously',\n            'proxyCheckKey' =\u003e 'Not a real key, obviously',\n            'mapquestKey' =\u003e 'Not a real key, obviously',\n            'blowOff' =\u003e 'site/nope',\n            'ignorables' =\u003e [\n                'acontroller' =\u003e ['ignore-me', 'ignore-that'],\n                'whitelist' =\u003e ['127.0.0.1', '24.99.155.86']\n            ]\n        ],\n        ...\n    ],\n```\nAs you see, you can add a custom 'blowoff' controller action.  The visitor will be passed in so you can display the name and blowoff message.\n\nA couple of things to note here about the 'ignorables' configuration array.  You can add a controller and actions to ignore as well as a whitelist of IP addresses to ignore.  These will not be added to the access log.\n\nUsage\n-----\n\n\n\nIf you want to find out information on the current user, you can get the visitor model from the module and use it like so:\n```php\n    $visitor = \\Yii::$app-\u003egetModule('visitor')-\u003evisitor;\n    // give a special hello to people in Atlanta or your ex wife\n    if ($visitor-\u003einfo-\u003ecity === 'Atlanta' || $visitor-\u003einfo-\u003eip_address === '99.203.4.238') {\n        echo \"Your city sucks balls\";\n    }\n```\n\nImporting Existing Apache Access Logs\n-----\n\nTo kickstart your visitor data, you can import apache2 logs, as long as you (not www-data) have permissions to view them and they are in the standard apache format.\n\nThis is achieved via the very excellent parser library which can be found at https://github.com/kassner/log-parser.\n\nBy default, it assumes that your access logs are at '/etc/httpd/logs' since that's where mine are.  You can specify another path as the first argument.\n\nThe second argument is for specifying which files you'd like to import.  By default, it looks for access*. but a comma delimted list with no spaces can be provided instead.\n\n```bash\n# The default, looks for /etc/httpd/logs/access*\nphp yii visitor/import/logs\n\n# Looks for /my/own/private/idaho/access*\nphp yii visitor/import/logs '/my/own/private/idaho'\n\n# Will process /etc/httpd/log/access_log-20180603 and /etc/httpd/log/access_log-20180610 ONLY.\nphp yii visitor/import/logs '/etc/httpd/logs' access_log-20180603,access_log-20180610\n```\n\nTo see it live, check out https://snooky.biz/visitor\n\nScreenshots!\n-----\n\nThe main screen\n![ipfilter1](https://user-images.githubusercontent.com/4065107/42129954-e352eaea-7ca1-11e8-8db8-8cb44ce4f2fc.png)\n\nDetail visitor view\n![ipfilter2](https://user-images.githubusercontent.com/4065107/42129951-e330717c-7ca1-11e8-9337-52f16c8c8a5e.png)\n\nUpdating the name and/or message for a visitor.\n![ipfilter3](https://user-images.githubusercontent.com/4065107/42129952-e33bce3c-7ca1-11e8-9fd2-9e06a9833a2f.png)\n\nThe default blocked user view. (As seen from Tor)\n![ipfilter4](https://user-images.githubusercontent.com/4065107/42129953-e3476580-7ca1-11e8-84cf-aef11158446b.png)\n\n[.](https://snooky.biz/post/section/Ragedump) [.](https://snooky.biz/post/the-sixth-general-order) [.](https://snooky.biz/post/legal-threats) [.](https://snooky.biz/post/taking-out-the-trash) [.](https://snooky.biz/post/jeez-babe-i-dont-know-whats-wrong) [.](https://snooky.biz/post/my-stupid-vitriol) [.](https://snooky.biz/post/the-drama-train-just-keeps-a-chuggin) [.](https://snooky.biz/post/hypocrisy) [.](https://snooky.biz/post/marjorie-snook-isnt-your-name) [.](https://snooky.biz/post/inconstant-hooer) [.](https://snooky.biz/post/mother-of-the-year)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnsnook%2Fyii2-visitors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnsnook%2Fyii2-visitors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnsnook%2Fyii2-visitors/lists"}