PHPackages                             digitalcorehub/laravel-ip-restriction - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. digitalcorehub/laravel-ip-restriction

ActiveLibrary[Security](/categories/security)

digitalcorehub/laravel-ip-restriction
=====================================

Restrict access to specific IP addresses.

v1.0.3(6mo ago)23MITPHPPHP ^8.2CI passing

Since Nov 13Pushed 6mo agoCompare

[ Source](https://github.com/DigitalCoreHub/laravel-ip-restriction)[ Packagist](https://packagist.org/packages/digitalcorehub/laravel-ip-restriction)[ Docs](https://github.com/digitalcorehub/laravel-ip-restriction)[ GitHub Sponsors](https://github.com/DigitalCoreHub)[ RSS](/packages/digitalcorehub-laravel-ip-restriction/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (12)Versions (5)Used By (0)

Laravel IP Restriction
======================

[](#laravel-ip-restriction)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a014afd1c9da1cec1332b8cda913ae38799c1a22b4bb7f6a8d1e83176ed49dd2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469676974616c636f72656875622f6c61726176656c2d69702d7265737472696374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitalcorehub/laravel-ip-restriction)[![Total Downloads](https://camo.githubusercontent.com/9dd933146e05809b0c6770bcf81cfbdf18be5a0b38d4da35aaef8c84f40be4df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469676974616c636f72656875622f6c61726176656c2d69702d7265737472696374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitalcorehub/laravel-ip-restriction)[![Build Status](https://camo.githubusercontent.com/e8a41b555344fb05feaba2c1e4161d28345e36e00826ee6cbcafa0216f4ab071/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6469676974616c636f72656875622f6c61726176656c2d69702d7265737472696374696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/digitalcorehub/laravel-ip-restriction)[![Quality Score](https://camo.githubusercontent.com/f103a529c590416bc5bcd6e1e9b22328f1bb6334c2cff01a5b1abc0dda3dedf4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6469676974616c636f72656875622f6c61726176656c2d69702d7265737472696374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/digitalcorehub/laravel-ip-restriction)[![StyleCI](https://camo.githubusercontent.com/fecbd1248f87480b95c8434abe9d68eb6863b09dcdd4c7d5ae92bb747e5473f7/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3132333435363738392f736869656c64)](https://github.styleci.io/repos/123456789)[![License](https://camo.githubusercontent.com/5988b9e870d4bc88e9ef3986e3cb051420f6b830b2d4fd9bd09c981134e31e1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6469676974616c636f72656875622f6c61726176656c2d69702d7265737472696374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitalcorehub/laravel-ip-restriction)

**Türkçe:** Uygulamanıza IP adreslerine göre erişimi kısıtlamak için güçlü ve esnek bir Laravel paketi. Bu paket, CIDR notasyonu desteği, proxy header işleme, önbellekleme ve detaylı loglama dahil olmak üzere kapsamlı IP filtreleme yetenekleri sağlar.

**English:** A powerful and flexible Laravel package for restricting access to your application based on IP addresses. This package provides comprehensive IP filtering capabilities including CIDR notation support, proxy header handling, caching, and detailed logging.

✨ Özellikler / Features
-----------------------

[](#-özellikler--features)

- 🔒 **IP Adres Filtreleme / IP Address Filtering** - Belirli IP adreslerine veya IP aralıklarına erişimi kısıtla / Restrict access to specific IP addresses or IP ranges
- 🌐 **CIDR Notasyonu Desteği / CIDR Notation Support** - IP aralığı kısıtlamaları için CIDR notasyonu kullan (örn: `192.168.1.0/24`) / Use CIDR notation for IP range restrictions (e.g., `192.168.1.0/24`)
- 🔄 **Proxy Desteği / Proxy Support** - Çeşitli proxy header'larını işle (Cloudflare, load balancer, vb.) / Handle various proxy headers (Cloudflare, load balancers, etc.)
- ⚡ **Önbellekleme / Caching** - Gelişmiş performans için yerleşik önbellekleme / Built-in caching for improved performance
- 📊 **Loglama / Logging** - Yetkisiz erişim denemelerinin kapsamlı loglanması / Comprehensive logging of unauthorized access attempts
- 🛠️ **Artisan Komutları / Artisan Commands** - Komut satırı üzerinden IP kısıtlamalarını yönet / Manage IP restrictions via command line
- 🧪 **İyi Test Edilmiş / Well Tested** - Kapsamlı test kapsamı / Comprehensive test coverage
- 📱 **IPv4 &amp; IPv6** - Hem IPv4 hem IPv6 adresleri için destek / Support for both IPv4 and IPv6 addresses
- ⚙️ **Yapılandırılabilir / Configurable** - Laravel config dosyaları aracılığıyla yüksek düzeyde yapılandırılabilir / Highly configurable through Laravel config files

📋 Gereksinimler / Requirements
------------------------------

[](#-gereksinimler--requirements)

- PHP 8.2 veya üzeri / PHP 8.2 or higher
- Laravel 10.0, 11.0 veya 12.0 / Laravel 10.0, 11.0 or 12.0
- Composer

🚀 Kurulum / Installation
------------------------

[](#-kurulum--installation)

Paketi Composer ile kurabilirsiniz / You can install the package via Composer:

```
composer require digitalcorehub/laravel-ip-restriction
```

Paket otomatik olarak service provider ve facade'ını kaydedecektir / The package will automatically register its service provider and facade.

⚙️ Yapılandırma / Configuration
-------------------------------

[](#️-yapılandırma--configuration)

Yapılandırma dosyasını yayınlayın / Publish the configuration file:

```
php artisan vendor:publish --tag=ip-restriction-config
```

Bu, aşağıdaki seçeneklerle `config/ip-restriction.php` dosyasını oluşturacaktır / This will create `config/ip-restriction.php` with the following options:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Allowed IP Addresses
    |--------------------------------------------------------------------------
    |
    | This array contains the IP addresses that are allowed to access your
    | application when using the IP restriction middleware.
    |
    */
    'allowed_ips' => [
        '127.0.0.1',        // Localhost
        '::1',              // IPv6 localhost
        '192.168.1.0/24',   // Local network range
        '10.0.0.0/8',       // Private network range
    ],

    /*
    |--------------------------------------------------------------------------
    | Cache Configuration
    |--------------------------------------------------------------------------
    |
    | Configure how long the allowed IPs list should be cached.
    | Set to null to disable caching.
    |
    */
    'cache_ttl' => 3600, // 1 hour in seconds

    /*
    |--------------------------------------------------------------------------
    | Logging Configuration
    |--------------------------------------------------------------------------
    |
    | Configure whether to log unauthorized access attempts.
    |
    */
    'log_attempts' => true,

    /*
    |--------------------------------------------------------------------------
    | Custom Error Message
    |--------------------------------------------------------------------------
    |
    | Customize the error message shown when access is denied.
    |
    */
    'error_message' => 'Access denied. Your IP address is not authorized.',
];
```

🎯 Kullanım / Usage
------------------

[](#-kullanım--usage)

### Temel Middleware Kullanımı / Basic Middleware Usage

[](#temel-middleware-kullanımı--basic-middleware-usage)

Middleware'i route'larınıza uygulayın / Apply the middleware to your routes:

```
// Bireysel route'ları koru / Protect individual routes
Route::get('/admin', function () {
    return view('admin.dashboard');
})->middleware('restrict_to_ip');

// Route gruplarını koru / Protect route groups
Route::middleware(['restrict_to_ip'])->group(function () {
    Route::get('/admin/dashboard', [AdminController::class, 'dashboard']);
    Route::get('/admin/users', [AdminController::class, 'users']);
    Route::get('/admin/settings', [AdminController::class, 'settings']);
});

// Controller'ları koru / Protect controllers
class AdminController extends Controller
{
    public function __construct()
    {
        $this->middleware('restrict_to_ip');
    }
}
```

### Facade Kullanımı / Using the Facade

[](#facade-kullanımı--using-the-facade)

Paketi programatik olarak da kullanabilirsiniz / You can also use the package programmatically:

```
use DigitalCoreHub\LaravelIpRestriction\Facades\LaravelIpRestriction;

// IP'nin izin verilip verilmediğini kontrol et / Check if an IP is allowed
if (LaravelIpRestriction::isIpAllowed('192.168.1.100')) {
    // IP'ye izin verildi / IP is allowed
}

// İstemci IP'sini al / Get client IP
$clientIp = LaravelIpRestriction::getClientIp();

// İzin verilen listeye IP ekle (sadece çalışma zamanında) / Add IP to allowed list (runtime only)
LaravelIpRestriction::addAllowedIp('203.0.113.1');

// İzin verilen listeden IP çıkar (sadece çalışma zamanında) / Remove IP from allowed list (runtime only)
LaravelIpRestriction::removeAllowedIp('203.0.113.1');

// Cache'i temizle / Clear cache
LaravelIpRestriction::clearCache();
```

### IP Adres Formatları / IP Address Formats

[](#ip-adres-formatları--ip-address-formats)

Paket çeşitli IP adres formatlarını destekler / The package supports various IP address formats:

```
'allowed_ips' => [
    '127.0.0.1',           // Tek IPv4 adresi / Single IPv4 address
    '::1',                 // Tek IPv6 adresi / Single IPv6 address
    '192.168.1.0/24',      // IPv4 CIDR aralığı / IPv4 CIDR range
    '2001:db8::/32',       // IPv6 CIDR aralığı / IPv6 CIDR range
    '10.0.0.0/8',          // Büyük IPv4 aralığı / Large IPv4 range
    '172.16.0.0/12',       // Özel IPv4 aralığı / Private IPv4 range
],
```

🛠️ Artisan Komutları / Artisan Commands
---------------------------------------

[](#️-artisan-komutları--artisan-commands)

Paket yararlı Artisan komutları içerir / The package includes helpful Artisan commands:

```
# Tüm izin verilen IP'leri listele / List all allowed IPs
php artisan ip-restriction:list

# IP kısıtlama cache'ini temizle / Clear the IP restriction cache
php artisan ip-restriction:list --clear-cache
```

🔧 Gelişmiş Yapılandırma / Advanced Configuration
------------------------------------------------

[](#-gelişmiş-yapılandırma--advanced-configuration)

### Özel Hata Mesajları / Custom Error Messages

[](#özel-hata-mesajları--custom-error-messages)

Erişim reddedildiğinde gösterilen hata mesajını özelleştirebilirsiniz / You can customize the error message shown when access is denied:

```
// config/ip-restriction.php dosyasında / In config/ip-restriction.php
'error_message' => 'Üzgünüz, konumunuzdan erişime izin verilmiyor. / Sorry, access from your location is not permitted.',
```

### Loglamayı Devre Dışı Bırakma / Disable Logging

[](#loglamayı-devre-dışı-bırakma--disable-logging)

Yetkisiz erişim denemelerinin loglanmasını devre dışı bırakmak için / To disable logging of unauthorized access attempts:

```
// config/ip-restriction.php dosyasında / In config/ip-restriction.php
'log_attempts' => false,
```

### Önbellekleme Devre Dışı Bırakma / Disable Caching

[](#önbellekleme-devre-dışı-bırakma--disable-caching)

İzin verilen IP listesinin önbelleklemesini devre dışı bırakmak için / To disable caching of the allowed IPs list:

```
// config/ip-restriction.php dosyasında / In config/ip-restriction.php
'cache_ttl' => null,
```

### Proxy Yapılandırması / Proxy Configuration

[](#proxy-yapılandırması--proxy-configuration)

Paket çeşitli proxy header'larını otomatik olarak işler / The package automatically handles various proxy headers:

- `HTTP_CF_CONNECTING_IP` (Cloudflare)
- `HTTP_X_FORWARDED_FOR` (Load balancer/proxy)
- `HTTP_X_FORWARDED` (Proxy)
- `HTTP_X_CLUSTER_CLIENT_IP` (Cluster)
- `HTTP_FORWARDED_FOR` (Proxy)
- `HTTP_FORWARDED` (Proxy)
- `HTTP_CLIENT_IP` (Proxy)
- `REMOTE_ADDR` (Standart / Standard)

🧪 Test Etme / Testing
---------------------

[](#-test-etme--testing)

Testleri çalıştırmak için / Run the tests with:

```
composer test
```

Veya kapsam ile çalıştırın / Or run with coverage:

```
composer test-coverage
```

📊 Loglama / Logging
-------------------

[](#-loglama--logging)

Loglama etkinleştirildiğinde, yetkisiz erişim denemeleri aşağıdaki bilgilerle loglanır / When logging is enabled, unauthorized access attempts are logged with the following information:

```
{
    "level": "warning",
    "message": "Unauthorized IP access attempt",
    "context": {
        "ip": "203.0.113.1",
        "user_agent": "Mozilla/5.0...",
        "url": "https://example.com/admin",
        "method": "GET",
        "timestamp": "2024-01-15T10:30:00.000000Z"
    }
}
```

🔒 Güvenlik Değerlendirmeleri / Security Considerations
------------------------------------------------------

[](#-güvenlik-değerlendirmeleri--security-considerations)

- **Her zaman HTTPS kullanın** / **Always use HTTPS** - Üretimde IP sahteciliğini önlemek için / in production to prevent IP spoofing
- **Proxy'nizi doğru yapılandırın** / **Configure your proxy correctly** - Gerçek IP adreslerinin geçirildiğinden emin olmak için / to ensure real IP addresses are passed
- **Logları düzenli olarak inceleyin** / **Regularly review logs** - Şüpheli erişim denemeleri için / for suspicious access attempts
- **Mümkün olduğunda geniş aralıklar yerine belirli IP aralıkları kullanın** / **Use specific IP ranges** rather than broad ranges when possible
- **IP kısıtlamalarının yanında ek kimlik doğrulama kullanmayı düşünün** / **Consider using additional authentication** alongside IP restrictions

🚀 Performans / Performance
--------------------------

[](#-performans--performance)

- **Önbellekleme / Caching**: IP listeleri gelişmiş performans için önbelleğe alınır / IP lists are cached for improved performance
- **Verimli eşleştirme / Efficient matching**: Optimize edilmiş IP eşleştirme algoritmaları / Optimized IP matching algorithms
- **Minimal yük / Minimal overhead**: Minimal performans etkisi olan hafif middleware / Lightweight middleware with minimal performance impact

🤝 Katkıda Bulunma / Contributing
--------------------------------

[](#-katkıda-bulunma--contributing)

Katkılarınızı memnuniyetle karşılıyoruz! / We welcome contributions! Detaylar için [Katkıda Bulunma Rehberi](CONTRIBUTING.md) / [Contributing Guide](CONTRIBUTING.md) sayfamıza bakın.

1. Repository'yi fork edin / Fork the repository
2. Özellik dalınızı oluşturun / Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Değişikliklerinizi commit edin / Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Dalı push edin / Push to the branch (`git push origin feature/amazing-feature`)
5. Pull Request açın / Open a Pull Request

📝 Değişiklik Günlüğü / Changelog
--------------------------------

[](#-değişiklik-günlüğü--changelog)

Son değişiklikler hakkında daha fazla bilgi için [CHANGELOG](CHANGELOG.md) sayfamıza bakın / Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

🐛 Hata Raporları / Bug Reports
------------------------------

[](#-hata-raporları--bug-reports)

Bir hata keşfederseniz, lütfen aşağıdaki bilgilerle bir issue açın / If you discover a bug, please open an issue with:

- Problemin net açıklaması / A clear description of the problem
- Sorunu yeniden üretme adımları / Steps to reproduce the issue
- Beklenen vs gerçek davranış / Expected vs actual behavior
- Ortam detaylarınız / Your environment details

🔐 Güvenlik Açıkları / Security Vulnerabilities
----------------------------------------------

[](#-güvenlik-açıkları--security-vulnerabilities)

Bir güvenlik açığı keşfederseniz, lütfen issue tracker kullanmak yerine  adresine e-posta gönderin / If you discover a security vulnerability, please send an email to  instead of using the issue tracker.

📄 Lisans / License
------------------

[](#-lisans--license)

MIT Lisansı (MIT) / The MIT License (MIT). Daha fazla bilgi için [Lisans Dosyası](LICENSE.md) / [License File](LICENSE.md) sayfamıza bakın.

🙏 Teşekkürler / Credits
-----------------------

[](#-teşekkürler--credits)

- [DigitalCoreHub](https://github.com/DigitalCoreHub)
- [Tüm Katkıda Bulunanlar](../../contributors) / [All Contributors](../../contributors)

📞 Destek / Support
------------------

[](#-destek--support)

- 📧 E-posta / Email:
- 🐛 Sorunlar / Issues: [GitHub Issues](https://github.com/digitalcorehub/laravel-ip-restriction/issues)
- 📖 Dokümantasyon / Documentation: [GitHub Wiki](https://github.com/digitalcorehub/laravel-ip-restriction/wiki)

---

[DigitalCoreHub](https://digitalcorehub.com) tarafından ❤️ ile yapıldı / Made with ❤️ by [DigitalCoreHub](https://digitalcorehub.com)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance66

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~115 days

Total

4

Last Release

199d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32592602?v=4)[Batuhan Haymana](/maintainers/1batu)[@1batu](https://github.com/1batu)

---

Top Contributors

[![1batu](https://avatars.githubusercontent.com/u/32592602?v=4)](https://github.com/1batu "1batu (11 commits)")

---

Tags

laravelDigitalCoreHublaravel-ip-restriction

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/digitalcorehub-laravel-ip-restriction/health.svg)

```
[![Health](https://phpackages.com/badges/digitalcorehub-laravel-ip-restriction/health.svg)](https://phpackages.com/packages/digitalcorehub-laravel-ip-restriction)
```

###  Alternatives

[spatie/laravel-ciphersweet

Use ciphersweet in your Laravel project

416718.4k1](/packages/spatie-laravel-ciphersweet)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
