CodeIgniter Forums
Problem in Filter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Problem in Filter (/thread-71981.html)



Problem in Filter - titounnes - 10-22-2018

Ihave code in Filter like this
PHP Code:
<?php

namespace App\Filters\API;

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

class 
GuestRequest implements FilterInterface
{
 
   public function before(RequestInterface $request)
 
   {

 
        //$req  = ( $request->getMethod()=='post' && $request->isAJAX() == TRUE$
 
       $req $request->getMethod();
 
       $ajx $request->isAJAX();

 
       if$ajx == true )
 
       {
 
               Config('App')->data = (object)[$req$ajx];
 
               Config('App')->time microtime(true);
 
               return true;

 
       }


 
       return Services::response()
 
           ->setStatusCode(401);

 
   
In local (OS : linix mint, php 7.2) run normal
in VPS (OS Centos, php 7.2)
always return 401, although my codes change to
if( $ajx == false)


RE: Problem in Filter - natanfelles - 11-20-2018

I think you've already solved that. But if a Response instance is returned the request will be responded.


RE: Problem in Filter - natanfelles - 11-20-2018

Oh, it looks like you can not return anything not empty. Even then the code should not be executed... Have you found a solution?