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

时间:2013-04-30 11:22:27

标签: php post page-refresh

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

更具体一点:

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

  • 这会影响查询的where条件。

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

  • 否则,条件包含一些id来获取特定数据 表格。

3 个答案:

答案 0 :(得分:2)

您最好的选择是使用PHP sessions以及$_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();

请注意,他们可以通过删除Cookie来清除此会话变量。

答案 1 :(得分:1)

页面顶部的

只包括

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

}

答案 2 :(得分:0)

我建议你查看请求

//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参数,请使用$ _POST而不是$ _REQUEST

相关问题