Download the PHP package abdulhadii777/laravel-ip-guard without Composer

On this page you can find all versions of the php package abdulhadii777/laravel-ip-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-ip-guard

Laravel IP Guard

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A powerful Laravel middleware package for IP-based access control with whitelist and blacklist support. Protect your application by allowing or blocking specific IP addresses with dynamic database management and a flexible priority system.

Current Version: v0.1.1

Features

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

The package will automatically register itself. You can publish the config file and migration with:

Or use the package's publish commands:

Then run the migration:

Configuration

After publishing the config file, you can configure the package in config/ip-guard.php. The package now uses database-driven IP management by default, with config as fallback:

Database Management

The package now uses database-driven IP management by default. IPs are stored in the ip_guards table with the following structure:

Database Schema

Usage

Dynamic IP Management

Via Facade

Via Artisan Commands

Via Model

Basic Middleware Usage

Apply the middleware to routes in your routes/web.php or routes/api.php:

Global Middleware

Add the middleware globally in app/Http/Kernel.php:

Controller Middleware

Apply in your controller constructor:

IP Matching Rules

The package supports exact IP matching only:

Exact IP Matching

Block All IPs

Priority Rules

The middleware follows this priority order:

  1. Environment Check: If IP_GUARD_ENABLED=false, all IPs are allowed (no restrictions)
  2. Blacklist Check (Highest Priority): If the client IP matches any blacklist rule, access is denied
    • * in blacklist blocks ALL IPs regardless of whitelist
  3. Whitelist Check: If whitelist is configured and IP matches, access is allowed
  4. Whitelist Enforcement: If whitelist is configured but IP doesn't match, access is denied
  5. Default: If whitelist is null/empty and IP is not blacklisted, access is allowed

Examples:

*Scenario 1: Blacklist with ``**

Scenario 2: Normal priority

Scenario 3: No restrictions

Scenario 4: Disabled

Proxy and Load Balancer Support

When your application is behind a proxy or load balancer, configure the ip_header option:

Make sure your Laravel application trusts the proxy by configuring TrustProxies middleware.

Error Responses

JSON Response (default)

Plain Text Response

Configure the response format in the config:

Advanced Examples

Admin Panel Protection

Environment-Based Control

Mixed Blacklist and Whitelist

Block Specific IPs

Development Environment

Temporary IP Management

Testing

The package includes comprehensive tests using Pest 4 with MySQL database testing.

Prerequisites

  1. MySQL Database: Ensure MySQL is running and accessible
  2. Test Database: Create a test database (or run the setup script)

Running Tests

Test Structure

The test suite includes:

Test Configuration

Tests use MySQL database with the following configuration:

Test Coverage

The test suite covers:

Custom Test Configuration

You can customize test database settings in phpunit.xml.dist:

Security Considerations

Troubleshooting

Common Issues

  1. Middleware not working: Ensure the middleware is properly registered and applied
  2. Wrong IP detected: Check your ip_header configuration and proxy setup
  3. Blocked legitimate users: Review your whitelist/blacklist rules and priority order
  4. IP guard not working: Check if IP_GUARD_ENABLED is set to true in your environment
  5. All IPs blocked: Check if * is in your blacklist (this blocks all IPs)
  6. Whitelist not working: Remember blacklist takes priority - check if IP is blacklisted first
  7. Invalid IP format: Ensure all IPs in your lists are valid IPv4 or IPv6 addresses
  8. Database connection issues: Check if migration has been run and database is accessible
  9. IP not found in database: Use php artisan ip-guard:manage list to check if IP exists
  10. Inactive IPs: Check if IP is disabled using php artisan ip-guard:manage toggle --id=X

Debug Mode

Enable Laravel's debug mode to see detailed error messages:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-ip-guard with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package abdulhadii777/laravel-ip-guard contains the following files

Loading the files please wait ...