Home > Article > Backend Development > How to prevent external malicious submissions from calling the ajax interface in PHP
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!