How do I make a PHP database connection to ionic 3?

0

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.

    
asked by Claudio Navarrete 24.01.2018 в 19:06
source

2 answers

0

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

    
answered by 25.01.2018 / 12:11
source
0

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

    
answered by 25.01.2018 в 16:58