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.
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.