Git Product home page Git Product logo

visitlog's Introduction

Laravel VisitLog

Total Downloads

Introduction

VisitLog is a simple Laravel 5 package that can be used to log visitor information and save it into database.

Features

  • Other than basic log such as IP, Browser and OS, it can also log Location information.
  • Allows to log both unique and non-unique visits based on IP.
  • Allows to cache the visits based on IP.
  • Allows to log authenticated user info.
  • Provides log viewer page out of box.
  • Provides basic http authentication for app users.
  • Ability to ban users by their IP

Note: VisitLog cannot detect same user/IP coming from some anonymizer so it cannot differentiate that.

Screenshot

Main Window

Note: Info in above screenshot is fake.

Requirements

  • PHP >= 5.5.9
  • Laravel 5

Installation

Install via composer

composer require sarfraznawaz2005/visitlog

For Laravel < 5.5:

Add Service Provider to config/app.php in providers section

Sarfraznawaz2005\VisitLog\VisitLogServiceProvider::class,

Add Facade to config/app.php in aliases section

'VisitLog' => Sarfraznawaz2005\VisitLog\Facades\VisitLog::class,

Run php artisan vendor:publish to publish package's config and migration file. You should now have config/visitlog.php file published. It will also publish migration file in database/migrations folder.

Run php artisan migrate to create visitlogs table in your database.

Config Options

  • route : Route where visit log will be available.
  • iptolocation : By default, only IP, Browser and OS info is logged. However if you set this option to true, it will also log Location info through https://ipstack.com/ service. Note: You will need to create account there and get your access key and specify that in visitlog config file.
  • cache : If iptolocation is set to true, this option can be used to cache the results instead of requesting Location info each time from https://ipstack.com/.
  • unique : If true, it will only log unique visits based on IP address. If false, it will log each visit even from same IP.
  • log_user : If true, it will also log authenticated user info.
  • user_name_fields : If log_user is true, this option can be used to specify name fields of user from your Users table in database.
  • visitlog_page : If true, a default log viewer page can be viewed at http//yourapp.com/your_route to see all the logs. Here your_route is the first option above.
  • http_authentication : If visitlog_page is true, this option can be used to show visit log page to only authenticated app users by asking them email and password via basic http authentication.

Saving Log Info

To save logs, just call save method of VisitLog facade: VisitLog::save();

Tip: If you want to save only unique logs based on IP, login or post-login page is good place to use the save method on because generally login page isn't visited again after user is authenticated. If you also want to save authenticated user, calling save method inside login post method seems to be good idea.

If however, you have set unique option to false and want to log all visits, calling save method in common location is good idea like base controller of your app.

Viewing Log Info

If config option visitlog_page is set to true, you can view all visit logs by browsing to http//yourapp.com/your_route.

Note: If you don't want to allow visitlog page to be publicly seen, set the option visitlog_page to false and now http//yourapp.com/your_route will result in 404 error.

In this case, you can still show log info in some authenticated area of your app by using all method of VisitLog facade: $visitLogs = VisitLog::all(); and it will give you Collection that you can iterate over and show in your own view file.

Credits

License

This code is published under the MIT License. This means you can do almost anything with it, as long as the copyright notice and the accompanying license file is left intact.

visitlog's People

Contributors

adjarriawan avatar alexmayo avatar amirasaran avatar djdino56 avatar gmsarates avatar ip2location avatar jrb-armonya avatar laravel-shift avatar minkyawnyunt avatar sarfraznawaz2005 avatar sarfrazonsupport avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

visitlog's Issues

error ""trim() expects parameter 1 to be string, array given"

{message: "trim() expects parameter 1 to be string, array given", exception: "ErrorException",…}
exception: "ErrorException"
file: "/home/jjoek/Documents/projects/centric/vendor/sarfraznawaz2005/visitlog/src/VisitLog.php"
line: 139
message: "trim() expects parameter 1 to be string, array given"
trace: [{function: "handleError", class: "Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"},…]

Laravel 8 not logging

I am using visitlog in laravel 8 . it is installed successfully. However nothing is logging into database. I am working in localhost.
Is it will not log in localhost

trim() expects parameter 1 to be string, array given

I am using Laravel 5.8 and im getting error ""trim() expects parameter 1 to be string, array given".After commenting this mentioned piece of code, it works properly.
if (is_array($data)) {
$data = array_map('trim', $data);
}
Please help me on that asap

Change the namespace

Thanks a lot for the package,

please consider changing the namespace to something simpler like Sarfraz or SarfrazNawaz

Fails installation for Laravel 7.19.1

Hi,

Can I know if anyone could install this package using latest laravel version? Is there any workaround for this? Installation is done using Cmder with Windows 10 operating system.

error stack trace

Log route visited

Thanks for this working package. Is it possible to log routes being visited?

Redundant parentheses cause an error

$ip = (app('VisitLog'))->getUserIP(); - this causes an error on PHP5.6.40 (syntax error, unexpected '->' (T_OBJECT_OPERATOR))
Parentheses are here redundant. Aren't they?
This is in Sarfraznawaz2005\VisitLog\Middleware\ipCheckMiddleware class.

Warning error with file_get_contents() method

I got a warning error with file_get_contents() method.

Warning: file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0

You should be used Http Facade.

Error if visit is during 1st hour of BST

An untrapped error occurs if a page is visited during the first hour of BST change.

At 01:00 on 27/03/2022, the clocks changed from 01:00 to 02:00 as we move from GMT to BST in the UK

Visits to the page between 2am and 3am appeared to cause an "invalid date/time format" error to be returned by Mysql (or a server error 500 if configured in production to do so)

This is likely to do with webserver/db server configuration being different in terms of the timezone configuration, but this is not something users on shared hosts have access to and this issue could be better handled in the codebase.

It was confirmed that Visitlog was causing the issue - as access to the pages were permitted immediately the call to VisitLog(); was commented out of the page, and the error re-occurred once the Visitlog(); command was put back in.

The issue ceased to occur after the first hour of BST had passed, (I assume because the web and DB server times became re-aligned.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.