Skip to content

lavaeagle/laravel-browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ee48421 · Jan 5, 2013

History

7 Commits
Nov 23, 2012
Sep 2, 2012
Sep 2, 2012

Repository files navigation

laravel-browser

Easy to access and read browser info

Read the browser class itself for all the info you can get.

/application/bundles.php

<?php
return array(
	'browser' => array('auto'=>true)
);

/application/bundles/browser/start.php

<?php

Autoloader::map(array(
	'Browser' => Bundle::path('browser').'browser.php'
));

Laravel\IoC::singleton('Browser', function()
{
	return new Browser($_SERVER['HTTP_USER_AGENT']);
});

Example usage: /application/routes.php

Route::filter('before', function()
{

    /*
    *   Track a user's visit
    */

    // Create the browser object
	Bundle::start('Browser');
	$browser = IoC::resolve('Browser');

    // Create the Eloquent object Visit
    $visit = new Visit;

    // Obviously for illegal purposes only
    $visit->location = Locate::get( 'city' ) . ', ' . Locate::get( 'state' ) . ', ' . Locate::get( 'country' );
    $visit->ip_address = Request::ip();

    $visit->request = URI::current();
    if( Auth::check() )
        $visit->user_id = Auth::user()->id;

    // Browser stats
    $visit->browser = $browser->getBrowser();
    $visit->browser_version = $browser->getVersion();
    $visit->platform = $browser->getPlatform();
    $visit->mobile = $browser->isMobile();
    $visit->robot = $browser->isRobot();
    $visit->save();

});

The Browser Class is created by: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

About

Easy to access and read browser info

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages