简体   繁体   English

如何确定发送到PHP脚本的POST数据来自何处?

[英]How do I identify where the POST data sent to a PHP script came from?

I have a ton of data collection forms on my website, and I wrote a PHP script to handle all the data. 我的网站上有大量的数据收集表格,并且编写了一个PHP脚本来处理所有数据。 All the forms have that one script as their action, and POST as the method. 所有表单都将一个脚本作为其动作,并将POST作为方法。 The handler emails a copy of the data to me, and I'd like for the emails I get to contain the URL of the form where they originated. 处理程序通过电子邮件将数据的副本发送给我,我希望我收到的电子邮件中包含其来源表格的URL。 Is there any way in PHP to get the url of the form which was submitted to the script? PHP中有什么方法可以获取提交给脚本的表单的网址? Or do I have to add an extra hidden field in every form with its URL? 还是我必须在每个表单的URL中添加一个额外的隐藏字段?

同样在电子邮件中发送以下变量:

$_SERVER['HTTP_REFERER'] 

如果要确保帖子仅来自您自己的表单,则可以在表单的隐藏字段中放置一次性令牌以进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM