Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel denny request by ip

//Run:
//php artisan make:middleware IpMiddleware

<?php

namespace AppHttpMiddleware;

use Closure;

class IpMiddleware
{

    public function handle($request, Closure $next)
    {
        if ($request->ip() != "192.168.0.155") {
        // here instead of checking a single ip address we can do collection of ips
        //address in constant file and check with in_array function
            return redirect('home');
        }

        return $next($request);
    }

}
// END OF FILE

// ---------------------
// app/Http/Kernel.php
//then add the new middleware class in the $middleware property of your app/Http/Kernel.php class.

protected $routeMiddleware = [
    //... other middlewares
    'ipcheck' => AppHttpMiddlewareIpMiddleware::class,
];
// ------------------
///In your route
then apply middelware to routes

Route::get('/', ['middleware' => ['ipcheck'], function () {
    // your routes here
}]);
Comment

PREVIOUS NEXT
Code Example
Php :: php list directory files by date 
Php :: remove element from xml on php 
Php :: php unique id 
Php :: phpspreadsheet set cell by column and row 
Php :: php switch case default 
Php :: php check if class exists 
Php :: laravel query builder select first 
Php :: email configuration for gmail in laravel 
Php :: foreach skip current iteration 
Php :: regex get text between braces 
Php :: migration rename column laravel 
Php :: how to completely delete php 
Php :: laravel auth without vue or bootstrap 
Php :: send axios request to php 
Php :: how to create migration in laravel 
Php :: laravel create model and migration 
Php :: ISO 8601 php 
Php :: php filters 
Php :: implode array keys in php 
Php :: wordpress get post featured image 
Php :: how to sent request in php 
Php :: laravel eloquent select case when 
Php :: get age in months php 
Php :: how to write javascript inside php 
Php :: time left laravel seconds 
Php :: belongs to many laravel 
Php :: php pdo error handling 
Php :: wp_query post by category taxonomy 
Php :: php artisan create controller inside folder 
Php :: SPA and keep some of the Laravel pages you need to have a route like this 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =