gpt4 book ai didi

php - 如何防止外部PHP脚本的 'manual execution'

转载 作者:行者123 更新时间:2023-12-04 00:33:31 25 4
gpt4 key购买 nike

简单来说,我在客户的整个网站上使用外部 PHP 脚本来实现各种目的,例如获取搜索结果、更新内容等。

我将这些脚本保存在一个目录中:

www.domain.com/scripts/scriptname01.php
www.domain.com/scripts/scriptname02.php
www.domain.com/scripts/scriptname03.php

等..

我通常使用 jQuery AJAX 调用来执行它们。

我想做的是找到一段代码,它会(从内部)检测这些脚本是通过 AJAX 从文件中执行还是由用户通过 URL 手动执行。

这可能吗??

我已经到处搜索并尝试了各种方法来处理 $_SERVER[] 数组,但仍然没有成功。

最佳答案

What I'm trying to do is find is a piece of code that will detect (from within) whether these scripts are being executed from a file via AJAX or MANUALLY via URL by the user.

IS THIS POSSIBLE??

不,不是 100% 可靠。您无法阻止客户端模拟 Ajax 调用。

不过,您可以测试一些 header ,即 X-Requested-With。它们会阻止不熟练的用户直接调用您的 Ajax URL。参见 Detect Ajax calling URL

关于php - 如何防止外部PHP脚本的 'manual execution',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7301964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com