我有一个网页(我们称之为 A.html)。 A.html 有一些 javascript 可以使用简单的 document.location="B.php" 将页面切换到动态 php 页面(我们称之为 B.php)。 B.php 根据它看到的 cookie 运行一个 mysql 查询,并返回一个基于 mysqli->affected_rows 变量的结果。但是,每次页面切换时,mysqli->affected_rows 都等于 0,即使 mysql 表确实按照预期的方式进行了更改。有趣的是,当我使用 url 栏(或刷新页面)直接转到 B.php 时,mysqli->affected_rows 为 1,就像它应该的那样。
看看 wireshark,两个 GET 请求之间的唯一区别是第二个(非 javascript)请求有一行 Cache-Control: max-age=0。有谁知道为什么这会影响任何事情,如果有办法解决这个问题?
编辑:这是代码
$req = $mysqli->prepare('update users set sts=NOW() where i=? and sid=? and sip=? and NOW()-sts <= '.$authentication_timeout.';');
if ($mysqli->error) {
log_mysql_error($mysqli);
die('Unexpected error:'.$mysqli->error);
}
$req->bind_param('sss',$uid,$sid,$_SERVER['REMOTE_ADDR']);
$req->execute();
print $mysqli->affected_rows;
$req->close();
最佳答案
如果确实是缓存让你的 brew 变味了,那我想是在做
document.location="B.php?nocache=" + new Date().getTime();
将解决问题。你能检查并验证是否是这样吗?
关于php - 缓存控制与 mysqli->affected_rows 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4485966/