PHP file only for AJAX | Sololearn: Learn to code for FREE!

+11

PHP file only for AJAX

Hi, Is there any way to declare that some PHP file is used only for AJAX and that it cannot be rendered in client browser when he types its URL?

7/11/2020 4:26:07 PM

Dominik Vladař

1 Answer

New Answer

+1

Not possible. There is no way to detect what sent the request to the server. However, you can send an extra field ajax=true with the request. Then in your PHP <?php if(empty($_GET['ajax'])){ exit(0); } Note that this can not stop browser request that append ?ajax=true to the url