This question already has answers here:
Origin is not allowed by Access-Control-Allow-Origin
(18 answers)
Closed 7 years ago.
I am developing a mobile application that uses js on the frontend and connects to a PHP backend which runs script against MongoDB database to return json data.Now everything was working fine as I tested the whole backend using localhost but now I want to upload the PHP files to some server so that I can test the whole thing using the actual mobile app.
So here's what I have done so far:-
I made my MongoDB database on MongoLab (they have a starter free plan) and I also uploaded my PHP files to google app engine (again for free). But now when I try to call a file using say Postman in google chrome, it shows Access-Allow-Control-Origin error, http://localhost is not allowed. I tried to google to find a solution to this but it didn't prove to be helpful as the error still persists.
So I switched to Amazon aws, fired up an ec2 instance, installed apache and PHP and uploaded my PHP files there, and I got the same Access-Allow-Control-Origin error.
So I guess my real question is can someone just walk me through the process of how I can upload my PHP files and have them connect to MongoDb database and then call them from localhost or from mobile app and have the result given to me.
P.S. - Sorry for such a long post but I just wanted to explain everything.
Add
header('Access-Control-Allow-Origin: http://localhost');
to the top of any page which has the problem.
Related
I am having trouble with several php files.
The problem is when I try to access my WebApp in said php files it results in a 503 error. Both files have API calls to different services that have worked perfectly until yesterday. When I remove the API call from the code the WebApp opens with no problem. I called both API services and they are both getting the API requests made from my server with no problem.
I've already exhausted all options to fix this error but came up with no results.
Any help is valid.
Thank you so much.
I've tried to change PHP version, but as I said there is no problem with PHP. Removing the API call makes the webapp function normally.
This question already has answers here:
WampServer & XAMPPserver automatically redirecting http to https (I don't want this)
(2 answers)
Closed 4 years ago.
I have a project virtually hosted in my computer(OS-Ubuntu , LAMP Stack).
The URL is I use to run my web app is http://ecommerce.dev . And It works fine in Firefox, but when I enter same URL in Google Chrome. I get an error saying This site can’t provide a secure connection ecommerce.dev sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
And the URL in the browser automatically changes to https://ecommerce.dev.
So I you guys to solve this problem.
This is because now google recognizes .dev as a Tld. Just change the url to http://ecommerce.test or something like that. You can use anything of your choice that doesn't resemble an existing Tld.
I'm trying to learn React by replicating a simple CRUD page I created earlier.
The old CRUD page was a Javascript/jQuery front-end with a form. It sent data via AJAX to a PHP backend page, and the PHP page interacted with a mySQL/mariaDB database.
Everything was locally hosted on my PC on XAMPP Apache, and everything worked fine.
I have now managed to replicate the front end using React, via Create React App and it's running on localhost:3000
I am now stuck. I don't know how to make my front-end (on localhost:3000) send data via AJAX to my back-end PHP page (on localhost:80 running on XAMPP Apache)
There are a lot of us PHP / mariaDB types out there who want to continue using that sub-stack as our back-end. The answers to this question will be enormously helpful in encouraging our crowd to try Create React App and React (I'm loving React btw!). (I was surprised that when I searched [create-react-app] [php] in StackOverflow, I got only 2 hits.)
Update: if this is off-topic for SO, then I'd appreciate suggestions on which SE I should post this on... thanks!
Answering my own question.
The basic problem is one of CORS (cross-origin resource sharing). The error one gets is (in the Chrome console):
No 'Access-Control-Allow-Origin' header is present on the requested resource.
During development only, this issue is easily resolved by adding this line of code to the top of the PHP file:
<?php
header("Access-Control-Allow-Origin: *");
This code should never be left there in production unless you're okay with anyone in the world accessing the PHP file API.
In actual production of this React app, one would expect that the JavaScript and the PHP files would share the same domain, so there won't be a CORS issue.
I am trying to make an android app with php in a backend. In this login page I am trying to send login credentials to php file so I can echo that and store that value in variables. And also My php file is stored on server of www.myurl.com/myfolder/login.php. I know a lot more about web development but this is my first experiment with android app. I even referred several online tutorials for this. All I see is using JSON and json_encode in php but that is not solving my problem. I think I am making some other mistake or is not able to locate an error.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Facebook API error 191
I have a Facebook page app running a competition entry that posts to the users wall upon entry.
I have it set up and working on my development server but when I try to host it from my dedicated server I get the error:
API Error Code: 191 API Error Description: The specified URL is not
owned by the application Error Message: Invalid redirect_uri: Given
URL is not permitted by the application configuration.
This suggests I haven't used the correct URL in my app settings, but I have checked and doubled checked and everything is okay.
It only seems to be a problem when hosted on my dedicated server as I have tested the app from servers and it works fine. For this project unfortunately it HAS to be hosted from my dedicated server.
Does anyone know a solution to this?
Each Facebook application requires it's own unique domain name. One domain name for one Facebook application.
Create new application for you production domain name.