Php 如何确保按钮在重置页面后仍保持不变

Php 如何确保按钮在重置页面后仍保持不变,php,arrays,post,session-variables,Php,Arrays,Post,Session Variables,我有以下资料: $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 } 因此,如果页面来自blah.php,则允许显示save按钮而不是submit。 我已经设置

我有以下资料:

$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
}
因此,如果页面来自blah.php,则允许显示save按钮而不是submit。 我已经设置好了,保存按钮更新数据库,提交按钮插入数据库

<?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 } ?>  
如何确保在单击“保存”后“保存”按钮仍保持不变。
例如,假设页面来自blah.php,然后进行一些更改并单击“保存”按钮,然后刷新页面,使其相信它不是来自$allowed_referer数组,因此它会将“保存”按钮更改为“提交”按钮,这是不好的,因为现在不保存当前id,“提交”将插入您只想保存的文件的副本。

您可以在第一次选中时,首先将用户提交的信息存储在已知的参考文件中:

$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
}
然后修改您的代码:

<?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 } ?> 

作为旁注,请记住,用户可以隐藏或修改发送到您的服务器的标题,因此关键功能不要依赖于此。

在$\u会话中存储标志?我不确定在哪里设置标志