不单击输入而运行的表单操作

发布于 2025-01-29 16:35:38 字数 340 浏览 0 评论 0原文

我希望表单操作中的代码在单击输入按钮时运行,但是每次刷新页面时,它都可以正常运行。

<form name="musluk" method="POST" action="<?php $res=mysqli_query($link,"UPDATE kullanicilar SET kredi= kredi +$musluk WHERE id=".$_SESSION['id']);?>">
    <input name="musluk" type="submit" class="btn btn-primary" value="Kazancı Al">
</form>

I want the code in the form action to run when I click the input button, but it works every time I refresh the page.

<form name="musluk" method="POST" action="<?php $res=mysqli_query($link,"UPDATE kullanicilar SET kredi= kredi +$musluk WHERE id=".$_SESSION['id']);?>">
    <input name="musluk" type="submit" class="btn btn-primary" value="Kazancı Al">
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2025-02-05 16:35:38

添加一个随机的nonce(仅使用过一次或类似的数字),例如在隐藏的输入字段中具有5位数字的数字,然后将其存储在$ _Session中。在操作中调用脚本时,请在运行脚本之前检查正确的NONCE号码。

$nonce = rand(1000, 9999) ;
$_SESSION["nonce"] = $nonce ; 

<input type="hidden"  name="nonce" value="<?php echo $nonce ?>">

在Aciton-Script跑中:

if(0 === strcmp($_POST["nonce"],$_SESSION["nonce"]){
    $runSuperCode() ;
}

Add a random nonce (number only used once or something like this), like a number with 5 digits, in a hidden input field, and store it in the $_Session. When calling the script in action, check if the correct nonce number was send before running the script.

$nonce = rand(1000, 9999) ;
$_SESSION["nonce"] = $nonce ; 

<input type="hidden"  name="nonce" value="<?php echo $nonce ?>">

And in the aciton-script run:

if(0 === strcmp($_POST["nonce"],$_SESSION["nonce"]){
    $runSuperCode() ;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文