Advertisement
fadlyshafa

Untitled

Sep 15th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Middleware;
  4.  
  5. use Closure;
  6.  
  7. class blockIp
  8. {
  9.     /**
  10.      * Handle an incoming request.
  11.      *
  12.      * @param  \Illuminate\Http\Request  $request
  13.      * @param  \Closure  $next
  14.      * @return mixed
  15.      */
  16.     public function handle($request, Closure $next)
  17.     {
  18.         $boleh = 0;
  19.         $alamat_ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  20.         // dd($alamat_ip);
  21.         $addr_ip = explode('.', $alamat_ip);
  22.         $ip = $addr_ip[0];
  23.        
  24.         $ipdantoko = explode('-', $ip);
  25.         $host_toko = $ipdantoko[0];
  26.        
  27.         $m_ip = \DB::table('ip')->get();
  28.        
  29.         foreach($m_ip as $mip)
  30.         {
  31.             $addr = $mip->addr;
  32.             if($addr == $host_toko){
  33.                 $boleh = 1;
  34.             }
  35.         }
  36.  
  37.         if($boleh == 0){
  38.             return \Response::make(view('errorr'), 404);
  39.         }
  40.  
  41.         return $next($request);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement