Welcome Guest, Not a member yet? Register   Sign In
How to show Custom View Error 429 Throttle
#4

PHP Code:
<?php namespace App\Filters;

use 
CodeIgniter\Filters\FilterInterface;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Config\Services;

class 
Throttle implements FilterInterface
{
        
/**
         * This is a demo implementation of using the Throttler class
         * to implement rate limiting for your application.
         *
         * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
         * @param array|null                                         $arguments
         *
         * @return mixed
         */
        
public function before(RequestInterface $request$arguments null)
        {
                
$throttler Services::throttler();

                
// Restrict an IP address to no more
                // than 1 request per second across the
                // entire site.
                
if ($throttler->check($request->getIPAddress(), 5MINUTE) === false)
                {
                    die(
view('/errors/html/error_429', ['url' => current_url()]));
                    return 
Services::response()->setStatusCode(429);
                }
        }

        
//--------------------------------------------------------------------

        /**
         * We don't have anything to do here.
         *
         * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
         * @param ResponseInterface|\CodeIgniter\HTTP\Response       $response
         * @param array|null                                         $arguments
         *
         * @return mixed
         */
        
public function after(RequestInterface $requestResponseInterface $response$arguments null)
        {
        }


Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply


Messages In This Thread
RE: How to show Custom View Error 429 Throttle - by nc03061981 - 10-16-2020, 10:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB