Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-检查页面刷新或在同一页面上发布数据_Php_Post_Page Refresh - Fatal编程技术网

PHP-检查页面刷新或在同一页面上发布数据

PHP-检查页面刷新或在同一页面上发布数据,php,post,page-refresh,Php,Post,Page Refresh,有没有办法知道页面是否刷新或数据是否发布在同一页面上 更具体地说: 我必须在同一页上发布数据 这会影响查询的where条件 如果页面已刷新,则where条件必须为1 否则,其中条件包含从中获取特定数据的id 桌子 在页面顶部仅包括 if(isset($_POST['name']) && $_POST['name']!=''){ //your code goes here } 我建议你检查一下你的要求 //Here goes the code session_start();

有没有办法知道页面是否刷新或数据是否发布在同一页面上

更具体地说:

  • 我必须在同一页上发布数据

  • 这会影响查询的where条件

  • 如果页面已刷新,则where条件必须为1

  • 否则,其中条件包含从中获取特定数据的id 桌子


在页面顶部仅包括

if(isset($_POST['name']) && $_POST['name']!=''){
//your code goes here

}

我建议你检查一下你的要求

//Here goes the code
session_start();
$counter = 0;
$counter = (isset($_SESSION['param'])) ? $counter++ : 0;

if($counter == 0)
    echo "data GET or POST";
else
    echo "refreshed";
**如果您只需要POST参数,请使用$\u POST而不是$\u REQUEST

您最好的选择是使用$\u POST中提交的数据。让我们假设在本例中,您具有以下形式:

<form action="this_page.php" method="post">
  <input type="text" name="important-info" />
  <input type="submit" value="Submit" />
</form>

同一页面的其他地方是PHP代码:

<?php
// example code
session_start();

if (!isset($_SESSION['previousVisitor']) && isset($_POST['important-info'])) {
  // this is a new visitor who has submitted the form
  $_SESSION['previousVisitor'] = true;
  // where is based on $_POST['important-info']
} else () {
  // where is 1
}

// close the session after you do what you need - this stops large pages causing hang
session_destroy();

您无法知道这是刷新还是第一个请求,除非您在第一个请求之后在服务器端的页面上添加了一些标志。我认为您的问题是,当用户刷新页面时,它不应该再次保存数据。也许这是一个问题?你不是在找刷新吗?在刷新时,发出了完全相同的请求。关于
会话的注释\u destroy()
是古怪的吗?前一段时间它让我头疼()-我认为值得一提。谢谢你的快速回复。嗯,我想这个问题可能被误解了。我在页面上有一个提交按钮,可以在同一页面上发布数据。我需要知道是点击了按钮还是刷新了页面。使用session previousvisitor,我总是得到1(在刷新和提交按钮点击的情况下),现在我更了解您的问题,我建议您阅读为PeeHaa埽 建议-因为从这个意义上讲,您并不是真正检查刷新,因为浏览器只会像按下按钮一样为您重新提交信息。还有其他的黑客-但我会先尝试这个链接。