sajidwarner/laravel-device-detector
A powerful Laravel package for browser detection, device detection, IP geolocation, VPN/Proxy detection, bot/robot detection, Tor detection, language detection, and platform detection — with built-in middleware, Laravel events, and Artisan commands. Supports Laravel 10, 11, 12, and 13 with PHP 8.1+.
Accept-Language headerlaratrack:test, laratrack:clear-cacheSec-CH-UA headers as primary detection method@mobile, @tablet, @desktop, @robot, @tor, @vpn, @proxycomposer require sajidwarner/laravel-device-detector
Laravel's auto-discovery will automatically register the service provider and facade.
If auto-discovery is disabled, add to config/app.php:
'providers' => [
SajidWarner\LaraTrack\LaraTrackServiceProvider::class,
],
'aliases' => [
'LaraTrack' => SajidWarner\LaraTrack\Facades\LaraTrack::class,
],
php artisan vendor:publish --provider="SajidWarner\LaraTrack\LaraTrackServiceProvider"
use SajidWarner\LaraTrack\Facades\LaraTrack;
$browser = LaraTrack::getBrowser(); // "Google Chrome"
$platform = LaraTrack::getPlatform(); // "Windows 10"
$type = LaraTrack::getDeviceType(); // "desktop" | "mobile" | "tablet"
$language = LaraTrack::getLanguage(); // "en-US", "bn-BD" ...
$isMobile = LaraTrack::isMobile(); // true / false
$isTablet = LaraTrack::isTablet(); // true / false
$isDesktop = LaraTrack::isDesktop(); // true / false
$isRobot = LaraTrack::isRobot(); // true / false
$isTor = LaraTrack::isTor(); // true / false
$isVpn = LaraTrack::isVpn(); // true / false
$isProxy = LaraTrack::isProxy(); // true / false
$location = LaraTrack::getLocation(); // array (when geolocation enabled)
$data = LaraTrack::detect();
/*
[
'browser' => 'Google Chrome',
'browser_version' => '120.0',
'platform' => 'Windows 10',
'device_type' => 'desktop',
'device_brand' => null,
'device_model' => null,
'is_mobile' => false,
'is_tablet' => false,
'is_desktop' => true,
'is_robot' => false,
'is_tor' => false,
'is_vpn' => false,
'is_proxy' => false,
'robot_name' => null,
'language' => 'en-US',
'ip' => '192.168.1.1',
'location' => [ // only when geolocation is enabled
'country' => 'Bangladesh',
'country_code' => 'BD',
'city' => 'Dhaka',
'state' => 'Dhaka Division',
'district' => 'Dhaka',
'zip' => '1000',
'latitude' => '23.72305',
'longitude' => '90.40860',
'timezone' => 'Asia/Dhaka',
'isp' => 'Ranks ITT',
'organization' => 'AS24323 Ranks ITT',
'currency' => 'BDT',
'calling_code' => '+880',
'is_eu' => false,
],
]
*/
use Illuminate\Http\Request;
use SajidWarner\LaraTrack\Facades\LaraTrack;
class HomeController extends Controller
{
public function index(Request $request)
{
$device = LaraTrack::detect($request);
if ($device['is_mobile']) {
return view('mobile.home', compact('device'));
}
if ($device['is_robot']) {
return response('Bot detected: ' . $device['robot_name']);
}
return view('home', compact('device'));
}
}
LaraTrack registers 6 middleware aliases automatically — no manual registration needed.
// Block all bots/crawlers
Route::middleware('laratrack.block-bots')->group(function () {
Route::get('/members', MembersController::class);
});
// Block Tor connections
Route::middleware('laratrack.block-tor')->group(function () {
Route::post('/checkout', CheckoutController::class);
});
// Block VPN and Proxy connections
Route::middleware('laratrack.block-vpn')->group(function () {
Route::post('/login', LoginController::class);
});
// Allow mobile devices only
Route::middleware('laratrack.mobile-only')->group(function () {
Route::get('/app', AppController::class);
});
// Allow desktop only
Route::middleware('laratrack.desktop-only')->group(function () {
Route::get('/dashboard', DashboardController::class);
});
// Block specific countries (inline)
Route::middleware('laratrack.block-countries:CN,RU,KP')->group(function () {
Route::get('/api', ApiController::class);
});
Block countries globally in config/laratrack.php:
'blocked_countries' => ['CN', 'RU', 'KP'],
Then just apply the middleware without parameters:
Route::middleware('laratrack.block-countries')->group(...);
// config/laratrack.php
'middleware' => [
'bot_message' => 'Bots are not allowed.',
'tor_message' => 'Tor connections are not allowed.',
'vpn_message' => 'VPN/Proxy connections are not allowed.',
'country_message' => 'Your country is not allowed.',
'mobile_only_message' => 'Please use a mobile device.',
'desktop_only_message' => 'Please use a desktop browser.',
'mobile_redirect' => '/download-app', // redirect desktop users
'desktop_redirect' => '/desktop-only', // redirect mobile users
],
LaraTrack fires Laravel events automatically when threats are detected. Listen to them in your EventServiceProvider or using #[AsEventListener].
// app/Providers/EventServiceProvider.php
protected $listen = [
\SajidWarner\LaraTrack\Events\BotDetected::class => [App\Listeners\HandleBot::class],
\SajidWarner\LaraTrack\Events\TorDetected::class => [App\Listeners\HandleTor::class],
\SajidWarner\LaraTrack\Events\VpnDetected::class => [App\Listeners\HandleVpn::class],
];
// BotDetected
$event->request; // Illuminate\Http\Request
$event->botName; // "Googlebot"
$event->ip; // "66.249.66.1"
// TorDetected
$event->request;
$event->ip;
// VpnDetected
$event->request;
$event->ip;
$event->type; // "vpn" or "proxy"
namespace App\Listeners;
use SajidWarner\LaraTrack\Events\BotDetected;
use Illuminate\Support\Facades\Log;
class HandleBot
{
public function handle(BotDetected $event): void
{
Log::warning("Bot detected: {$event->botName} from IP {$event->ip}");
}
}
Disable events in config if not needed:
'fire_events' => false,
Test LaraTrack detection from the terminal with any User-Agent string:
# Default Chrome UA
php artisan laratrack:test
# Custom User-Agent
php artisan laratrack:test "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15"
# With IP (for geolocation)
php artisan laratrack:test "Mozilla/5.0 Chrome/120.0.0.0" --ip=8.8.8.8
Example output:
LaraTrack Detection Result
─────────────────────────────────
+──────────────+──────────────────────+
| Field | Value |
+──────────────+──────────────────────+
| Browser | Google Chrome 120.0 |
| Platform | Windows 10 |
| Device Type | desktop |
| Is Mobile | No |
| Is Robot | No |
| Is Tor | No |
| Is VPN | No |
| Language | en-US |
| IP | 8.8.8.8 |
+──────────────+──────────────────────+
php artisan laratrack:clear-cache
Clears cached Tor exit nodes and all geolocation results.
@mobile
<p>Shown only on mobile</p>
@endmobile
@tablet
<p>Shown only on tablets</p>
@endtablet
@desktop
<p>Shown only on desktop</p>
@enddesktop
@robot
<p>Bot/crawler detected</p>
@endrobot
@tor
<p>Tor browser detected</p>
@endtor
@vpn
<p>VPN connection detected</p>
@endvpn
@proxy
<p>Proxy connection detected</p>
@endproxy
Get real-time location data for any visitor IP using ipgeolocation.io.
Free plan: 30,000 requests/month — no credit card required.
🔗 Sign up here (free): https://app.ipgeolocation.io/signup?referral=AFF-YWEVCOJFNY
.env file (never commit your API key to git):LARATRACK_GEO_ENABLED=true
LARATRACK_GEO_API_KEY=your_own_api_key_here
$location = LaraTrack::getLocation();
echo $location['country']; // Bangladesh
echo $location['city']; // Dhaka
echo $location['timezone']; // Asia/Dhaka
echo $location['isp']; // Ranks ITT
echo $location['currency']; // BDT
echo $location['calling_code']; // +880
| Field | Description | Example |
|---|---|---|
country |
Full country name | Bangladesh |
country_code |
ISO 2-letter code | BD |
city |
City name | Dhaka |
state |
State / Province | Dhaka Division |
district |
District | Dhaka |
zip |
Postal / ZIP code | 1000 |
latitude |
Latitude | 23.72305 |
longitude |
Longitude | 90.40860 |
timezone |
Timezone name | Asia/Dhaka |
isp |
Internet Service Provider | Ranks ITT |
organization |
AS organization | AS24323 Ranks ITT |
currency |
Currency code | BDT |
calling_code |
Phone country code | +880 |
is_eu |
EU member country | false |
| Browser | Detection Method |
|---|---|
| Google Chrome | User-Agent + Sec-CH-UA |
| Mozilla Firefox | User-Agent |
| Safari | User-Agent |
| Microsoft Edge | User-Agent + Sec-CH-UA |
| Opera / Opera GX | User-Agent |
| Brave | User-Agent + Sec-CH-UA |
| Vivaldi | User-Agent |
| Tor Browser | User-Agent |
| Kahf Browser | X-Requested-With header |
| DuckDuckGo Browser | X-Requested-With + User-Agent |
| Samsung Internet | User-Agent |
| UC Browser | User-Agent |
| Internet Explorer | User-Agent |
| Chromium | User-Agent |
| Brand | Models Detected |
|---|---|
| Apple | iPhone, iPad (with model number) |
| Samsung | Galaxy series, SM- model codes |
| Xiaomi | Redmi, Mi, Poco series |
| Huawei | Huawei, Honor series |
| OnePlus | All OnePlus models |
| Oppo | All Oppo models |
| Vivo | All Vivo models |
| Pixel series | |
| Motorola | Moto series |
| Nokia | All Nokia models |
| LG | All LG models |
| Sony | All Sony models |
| HTC | All HTC models |
Googlebot, Bingbot, Yahoo Slurp, DuckDuckBot, Baiduspider, YandexBot, Sogou, Exabot, facebot, ia_archiver, Facebookbot, Twitterbot, LinkedInBot, WhatsApp, Telegram, Discordbot, Slackbot, Applebot, AhrefsBot, SemrushBot, MJ12bot, DotBot, Screaming Frog, SEOkicks, and more.
Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista, Windows XP, macOS, iOS (iPhone), iOS (iPad), iPadOS, Android, Ubuntu, Linux, Chrome OS, BlackBerry, Windows Phone.
Full config/laratrack.php:
return [
// Tor Detection
'enable_tor_detection' => env('LARATRACK_TOR_DETECTION', true),
'tor_cache_duration' => env('LARATRACK_TOR_CACHE', 3600),
'tor_exit_node_url' => env('LARATRACK_TOR_URL', 'https://check.torproject.org/exit-addresses'),
// Robot Detection
'enable_robot_detection' => env('LARATRACK_ROBOT_DETECTION', true),
// IP Geolocation
'enable_ip_geolocation' => env('LARATRACK_GEO_ENABLED', false),
'ip_geolocation_api_key' => env('LARATRACK_GEO_API_KEY', ''),
'ip_geolocation_api_url' => env('LARATRACK_GEO_URL', 'https://api.ipgeolocation.io/v3/ipgeo'),
'ip_geolocation_cache_duration' => env('LARATRACK_GEO_CACHE', 3600),
// Events
'fire_events' => env('LARATRACK_FIRE_EVENTS', true),
// Country Blocking
'blocked_countries' => [],
// Middleware Messages & Redirects
'middleware' => [
'bot_message' => 'Access denied: bots are not allowed.',
'tor_message' => 'Access denied: Tor connections are not allowed.',
'vpn_message' => 'Access denied: VPN/Proxy connections are not allowed.',
'country_message' => 'Access denied: your country is not allowed.',
'mobile_only_message' => 'This page is only available on mobile devices.',
'desktop_only_message' => 'This page is only available on desktop.',
'mobile_redirect' => null,
'desktop_redirect' => null,
],
];
| PHP Version | Supported |
|---|---|
| 8.1 | ✅ |
| 8.2 | ✅ |
| 8.3 | ✅ |
| 8.4 | ✅ |
| 8.5+ | ✅ (future-compatible via ^8.1) |
| Laravel Version | Supported |
|---|---|
| 10.x | ✅ |
| 11.x | ✅ |
| 12.x | ✅ |
| 13.x | ✅ |
composer test
36 tests · 86 assertions · all passing ✅
GET /laratrack/test
Returns JSON with full detection data including headers. Disabled automatically in production.
If you discover any security issues, please email bestcyberking@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
For support, please open an issue on GitHub.
Keywords: laratrack, laravel device detector, laravel browser detection, laravel user agent parser, laravel mobile detection, laravel ip geolocation, laravel bot detection, laravel tor detection, laravel vpn detection, laravel middleware, php device detection, laravel package
How can I help you explore Laravel packages today?