We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon CORS ERROR

Can someone please explain me what is the difference between using:

    $requestUri = '/' . str_replace($di->get('url')->getBaseUri(), '', $_SERVER['REQUEST_URI']);
    if ($requestUri == '') {
        $requestUri = '/';
    }
    $app = new Application($di);
     $response = $app->handle($requestUri);
    $response->setHeader('Access-Control-Allow-Origin', '*');
     $response->setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS');
     $response->setheader('Access-Control-Expose-Headers', 'Content-Length, X-JSON');
     $response->setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type,  X-Auth-Token, Accept');
     $response->setHeader('Access-Control-Allow-Credentials', 'true');
     $response->send();

AND using this:

       $origin = $app->request->getHeader("ORIGIN") ? $app->request->getHeader("ORIGIN") : '*';
    $app->response->setHeader("Access-Control-Allow-Origin", $origin)
                    ->setHeader("Access-Control-Allow-Methods", 'GET,PUT,POST,DELETE,OPTIONS')
                    ->setHeader("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type, Authorization')
                    ->setHeader("Access-Control-Allow-Credentials", true);

   $app->response->sendHeaders();

We're going to need more information on what you're expecting, what isn't working, and what you've already tried to solve the problem.