I made a connection to the database with a PHP API with the slim framework and even though I feel that it is wrong because it sends me CORS error, all the possible solutions were made.
I made a connection to the database with a PHP API with the slim framework and even though I feel that it is wrong because it sends me CORS error, all the possible solutions were made.
You must indicate in your php the acceptance of access from sources outside your server
header("Access-Control-Allow-Origin: *");
That line should be placed at the beginning of your php code before any response output.
you can also limit the access to an ip or domain, or groups of these
header("Access-Control-Allow-Origin: hitcel.com");
That way we only give access to the domain name or requests that come from the domain hitcel.com for example.
You can also specify which methods your api accepts:
Access-Control-Allow-Methods: POST, GET
This applies to any request that is received from external agents to your server, either from ionic APPs, phonegap, android, etc.
I hope I helped you. Greetings
What Carlos Quintera says is the right way, you have to give him access to the origins outside your server .... If you have Mac, a fast tip would be to use the Safari developer tool and deactivate the CORS, and all It flows without problems.
If you do not have the tool active you can go to: Preferences - > Advanced. and here check the box "See development menu in the bar".
When you already have it active, select "Development" and then select the option "Deactivate CORS restrictions"
Greetings