How to resolve CORS error in PHP Codeigniter for Ionic App APIs?

edited March 2021 in PHP

For Ionic project, We need to do some changes in backend functionalities.

Add following code in index.php file of codeigniter project:

<?php

header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);  

        header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');

        header('Access-Control-Max-Age: 1000');

        header('Access-Control-Allow-Headers: Content-Type,ResponseType, Authorization, X-Requested-With');

?>


That''s it, sit back relaxed😁, Issue will be resolved.

Tagged:
Sign In or Register to comment.