Prevent direct access to a PHP page

There is no way of guaranteeing that they’re accessing it through AJAX. Both direct access and AJAX access come from the client, so it can easily be faked.

Why do you want to do this anyways?

If it’s because the PHP code isn’t very secure, make the PHP code more secure. (For example, if your AJAX passes the user id to the PHP file, write code in the PHP file to make sure that is the correct user id.)

Leave a Comment