How can I get my PHP script to only answer requests if the requesting script is on the same domain?
** Edit:
The PHP file is being accessed by an ajax request and is proxy, so I don’t want others directly requesting it to come up, is this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
$_SERVER['REMOTE_ADDR']to compare the IP of the user requesting the page. Or you could simply make it a command line script that (obviously) requires you to run it from the command line.edit:
You want to prevent people from using that script other than via AJAX? Impossible, as AJAX itself is executed by the client, as such the request starts there. And it will be always possible to call that script alone; you can make it harder, but you won’t be able to prevent it.