Home  >  Article  >  Backend Development  >  How to prevent external malicious submissions from calling the ajax interface in PHP

How to prevent external malicious submissions from calling the ajax interface in PHP

墨辰丷
墨辰丷Original
2018-06-04 09:31:112524browse

This article briefly introduces how to prevent external malicious calls to the ajax interface to save traffic and reduce server pressure.

If we use the ajax interface written by our own website for ourselves, we should limit the source domain name and determine the source.

Note: Replace www.jb51.net with your own domain name.

Copy code The code is as follows:

//Judge the source
if(!isset($_SERVER['HTTP_REFERER']) || ! stripos($_SERVER['HTTP_REFERER'],'www.jb51.net')) {
echo 'cann`t access';
exit();
}

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

phpDetailed explanation of file upload class examples

phpImplementation Methods and meanings of singleton mode

php html5 ajax methods and examples for uploading images

The above is the detailed content of How to prevent external malicious submissions from calling the ajax interface in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn