[英]How can I make sure my button stays even after it has reset the page
I have the following: 我有以下几点:
$allowed_referer = array("https://localhost/**blah.php**"); //add the allowed sites in this array
$referal = $_SERVER['HTTP_REFERER'];
if (in_array($referal, $allowed_referer)){
//Do-stuff
}
so if the page is coming from blah.php the save button is allowed to be displayed instead of submit. 因此,如果页面来自blah.php ,则可以显示保存按钮,而不是提交。 I have it set up where the save button updates the database and the submit button inserts into the database.
我在保存按钮更新数据库并将提交按钮插入数据库的地方进行了设置。
<?php if (!in_array($referal, $allowed_referer)){ ?>
<button type="submit" name="submit" value="submit-new"> Submit </button>
<?php }
else { ?>
<button type="submit" name="submit" value="save-new"> Save </button>
<?php } ?>
How can I make sure the save button stays even after clicking on save. 我如何确保即使单击保存后保存按钮仍然存在。
for example, lets say the page is coming from blah.php, then you make some changes and click the save button, then it refreshes the page which makes it believe it is not coming from "$allowed_referer" array, so it will then change the save button to the "submit" button, which is bad because now instead of saving that current id, submit will insert a duplicate of the file you just wanted to save. 例如,假设该页面来自blah.php,然后进行一些更改,然后单击“保存”按钮,然后刷新页面,使其认为它不是来自“ $ allowed_referer”数组,因此它将更改将保存按钮保存到“提交”按钮上,这很糟糕,因为现在提交而不是保存该当前ID,而是插入一个您想要保存的文件的副本。
You could store the information user in comming from a known referer
in the first place when you ckeck it the first time: 当您第一次点击时,您可以将信息
user in comming from a known referer
存储在第一位user in comming from a known referer
的地方:
$allowed_referer = array("https://localhost/**blah.php**"); //add the allowed sites in this array
$referal = $_SERVER['HTTP_REFERER'];
if (in_array($referal, $allowed_referer)){
//Store a flag in the session
$_SESSION['come_from_known_referer'] = true;
//Do-stuff
}
And then modify your code: 然后修改您的代码:
<?php if (!isset($_SESSION['come_from_known_referer'])){ ?>
<button type="submit" name="submit" value="submit-new"> Submit </button>
<?php } else { ?>
<button type="submit" name="submit" value="save-new"> Save </button>
<?php } ?>
As a sidenote, remember that a user can hide or modify the headers send to your server so do not rely on this for critical functionalities. 作为旁注,请记住,用户可以隐藏或修改发送到您的服务器的标头,因此不要依赖此标头来获得关键功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.