Access to fetch has been blocked by CORS policy

I’m trying to connect a React application to a MySQL database on InfinityFree using some PHP scripts uploaded to the same InfinityFree server. According to the documentation, it should be possible, but I’m encountering an error:

Access to fetch at ‘https://arbolgenealogico.rf.gd/api-php-react/guardar_usuario.php’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

But I have CORS enabled

What documentation?

Because you cannot actually do that since InfinityFree is a webhosting provider, not a database hosting provider:

5 Likes

I am afraid that what you’re describing is not possible because of this:

3 Likes

It will still be blocked on free hosting

2 Likes

You can host a React frontend application with us that talks to a PHP backend also hosted by us. However, both the React and PHP code must be uploaded on our hosting, and accessed from the same hostname. Our hosting does not support CORS from other domains, including local domains.

So for local development, please consider running a local PHP+MySQL stack, such as XAMPP, to host a local copy of your PHP application to test your React code with.

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.