isAJAX example


    public function run(float $startTime, float $totalTime, RequestInterface $request, ResponseInterface $response): string
    {
        $data = [];
        // Data items used within the view.         $data['url']             = current_url();
        $data['method']          = strtoupper($request->getMethod());
        $data['isAJAX']          = $request->isAJAX();
        $data['startTime']       = $startTime;
        $data['totalTime']       = $totalTime * 1000;
        $data['totalMemory']     = number_format((memory_get_peak_usage()) / 1024 / 1024, 3);
        $data['segmentDuration'] = $this->roundTo($data['totalTime'] / 7);
        $data['segmentCount']    = (int) ceil($data['totalTime'] / $data['segmentDuration']);
        $data['CI_VERSION']      = CodeIgniter::CI_VERSION;
        $data['collectors']      = [];

        foreach ($this->collectors as $collector) {
            $data['collectors'][] = $collector->getAsArray();
        }

        
<?= esc(strtoupper($request->getMethod())) ?></td> </tr> <tr> <td>IP Address</td> <td><?= esc($request->getIPAddress()) ?></td> </tr> <tr> <td style="width: 10em">Is AJAX Request?</td> <td><?= $request->isAJAX() ? 'yes' : 'no' ?></td> </tr> <tr> <td>Is CLI Request?</td> <td><?= $request->isCLI() ? 'yes' : 'no' ?></td> </tr> <tr> <td>Is Secure Request?</td> <td><?= $request->isSecure() ? 'yes' : 'no' ?></td> </tr> <tr> <td>User Agent</td> <td>
$httpMethods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH', 'OPTIONS'];

        if (in_array($valueUpper$httpMethods, true)) {
            return strtoupper($this->getMethod()) === $valueUpper;
        }

        if ($valueUpper === 'JSON') {
            return strpos($this->getHeaderLine('Content-Type'), 'application/json') !== false;
        }

        if ($valueUpper === 'AJAX') {
            return $this->isAJAX();
        }

        throw new InvalidArgumentException('Unknown type: ' . $type);
    }

    /** * Determines if this request was made from the command line (CLI). */
    public function isCLI(): bool
    {
        return false;
    }

    public function storePreviousURL($uri)
    {
        // Ignore CLI requests         if ($this->isWeb()) {
            return;
        }
        // Ignore AJAX requests         if (method_exists($this->request, 'isAJAX') && $this->request->isAJAX()) {
            return;
        }

        // Ignore unroutable responses         if ($this->response instanceof DownloadResponse || $this->response instanceof RedirectResponse) {
            return;
        }

        // Ignore non-HTML responses         if (strpos($this->response->getHeaderLine('Content-Type'), 'text/html') === false) {
            return;
        }
public function before(RequestInterface $request$arguments = null)
    {
        if ($request instanceof IncomingRequest) {
            return;
        }

        $security = Services::security();

        try {
            $security->verify($request);
        } catch (SecurityException $e) {
            if ($security->shouldRedirect() && ! $request->isAJAX()) {
                return redirect()->back()->with('error', $e->getMessage());
            }

            throw $e;
        }
    }

    /** * We don't have anything to do here. * * @param array|null $arguments * * @return void */
Home | Imprint | This part of the site doesn't use cookies.