gpt4 book ai didi

php - 确定 $_POST 的来源

转载 作者:可可西里 更新时间:2023-11-01 00:15:44 25 4
gpt4 key购买 nike

有没有一种简单的方法可以在 PHP 中找出 post 变量的来源?

example.com/formone.php 上的表单

<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>

example.com/formtwo.php 上的表单

<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>

我知道我可以使用隐藏输入,但我想知道 PHP 是否有测试 POST 源的方法。

最佳答案

虽然您可能会使用 HTTP_REFERER 服务器变量,it is not very reliable .您最好的选择是使用隐藏字段。

另一种选择是将您的提交 input 切换为提交 button。这样你就可以传递一个值,保留按钮的标签,并在你的 test.php 页面中测试它:

<button name="submit" type="submit" value="form1">Submit</button>

然后在您的 PHP 文件中测试:

if( $_POST['submit'] == "form1" )
// do something

关于php - 确定 $_POST 的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11401710/

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