为什么每次我刷新页面时,数据库中都会发布一个新的评估

  • 本文关键字:数据库 布一个 评估 刷新 php
  • 更新时间 :
  • 英文 :


我的代码现在所做的是在数据库中发布会话,每次刷新此页面时,它都会一次又一次地发布相同的会话。我不明白为什么?解决方案可能很简单,但我什么都试过了。希望能得到一些帮助。

<?php
session_start();

require '../../required/connection.php';
require '../../required/functions.php';
if (!isset($_SESSION['alive']))
{
$id = $_GET['trxid'];
$_SESSION['alive'] = uniqid();
$currentSession = $_SESSION['alive'];
$checkQuery = "SELECT token FROM request_data WHERE token='$currentSession'";
$checkResult = mysqli_query($con, $checkQuery);
$row = mysqli_num_rows($checkResult);
if($row < 1)
{
$firstQuery = "INSERT INTO request_data (token, link) VALUES ('$currentSession', '$id')";
$firstResult = mysqli_query($con, $firstQuery);
}
}

我认为您的connection.phpfunctions.php出现了问题。是否也可能是服务器错误导致了这种行为?此外,可能是您修改了php.ini中会话的配置(例如生存期(?

以下示例基于您的代码,可在phpfiddle.org 页面上使用

<?php
session_start();
// just for testing - you can comment it in and out
//$_SESSION['alive'] = null;
if (!isset($_SESSION['alive'])) {
echo 'FALSE; <br/>';
$_SESSION['alive'] = uniqid();
echo 'AFTER = "'. $_SESSION['alive'] . '"'; 
} else {
echo 'TRUE = "'. $_SESSION['alive'] . '"'; 
}
?>

最新更新