如果服务器调用它,如何仅运行PHP脚本 [英] How to only run PHP script if server calls it

查看:208
本文介绍了如果服务器调用它,如何仅运行PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,只有在服务器本身调用它时,该脚本才能运行. 像这样:form().submit运行一个AJAX请求以发布表单数据.我不想开发一个哈希解码和编码系统来证明是否允许该请求.

I have a PHP script and this shall only run if the server itself calls it. Like this: form().submit runs an AJAX request to POST the form data. I don't want to develop a hash decode and encode system to proof if the request is allowed or not.

是否容易检查服务器运行脚本"或客户端是否要运行脚本?如果没有,我可以使用.htpasswd

Is there an easy possibility to check if the "server runs the script" or if the client wants to run the script? If not, I may use .htpasswd

推荐答案

您可以按照以下步骤进行操作;

You can do that with following steps;

1)将php脚本放置在Web文档根目录之外,例如/usr/local/phpscripts/

1) Put your php script outside of your web document root like /usr/local/phpscripts/

2)从您的代码中运行该脚本,例如;

2) Run this script from your code like;

$output = shell_exec('php /usr/local/phpscripts/your_script.php');

这样做,只有您的服务器才能调用您的脚本.网络用户无法访问该php脚本来执行

By doing this, only your server can call your script. Web user cannot access this php script to execute

这篇关于如果服务器调用它,如何仅运行PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆