简体   繁体   English

我如何确保即使重置页面后我的按钮仍然停留

[英]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.

相关问题 如何确保我的 PHP api 只能由特定的 javascript 页面使用 - How can I make sure that my PHP api can only be used by a specific javascript page 如何确保对服务器的请求来源合法? - how can I make sure that the origin of the request to my server is legit? 如何确保只有从特定功能重定向的用户才能访问我的网站页面? - How can I make sure that a user visits a page of my site only if he's redirected from a specific function? 如何在具有安全功能的注销页面上添加注销按钮? - How can I add a logout button to my logout page which has security features? 如何确保页面已被查看X秒? - How to make sure, that a page has been viewed for X seconds? 如何确保没有登录就无法访问除登录页面之外的其他页面? - How do I make sure that no other page apart from login page can be accessed without logging in? 如何确保输入整数在表单提交时保持整数 - How to make sure an Input Integer stays an Integer on Form Submit 如何使多个计时器即使页面刷新也不在php中重置? - How to make a multiple timer not to reset in php even if the page refreshes? 如何确保用户只按一下我的喜欢按钮? - How do I make sure my like button is pressed only once by user? 如何确定页面的某些部分不受CSS更改的影响? - How do I make sure certain portions of my page are unaffected by CSS changes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM