Use file_get_contents to solve ajax domain cracking problems
In ajax applications, files are called in different domains, and browsers warn or even block such operations for security purposes by default. If it is IE, a warning window will pop up asking if you want to continue the operation. only when you agree with IE will you call the file that breaks down the domain. Other browsers, such as Firefox and Opera, receive an error by default to prevent external domain files from being called. This will give users a poor operation experience. if you want to solve this problem by modifying the security settings of the browser, it is unrealistic, preferably on the server side.
On the server side, you can use a file in the same domain as the proxy file. This Proxy file will get the content of the external domain file and then pass it to ajax. In this way, ajax does not call the external domain file, but calls the Proxy file of the same domain, and the security problem is solved.
If your server supports PHP, you can use the file_get_contents function to obtain other file content. For details about its usage, see the file_get_contents usage page on the official PHP website. Below is a simple example of this page.
The code is as follows:
$ ServerAddress = 'http: // s.bitsCN.com ';
// Obtain the external domain file content
$ RandomNumber = file_get_contents ($ serverAddress );
// Output Content
Echo $ randomNumber;
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service