2

我注意到 PHP 已经插入了两次相同的数据,即使是一个简单的查询,下面是我的索引文件:

<?php
require("constants.php"); //contains database settings
$database = new PDO("$type:host=$host;dbname=$name", $user, $pass); 
$query = $database->prepare('INSERT into test (test) VALUES (?)');
$query->execute(array(rand()));
echo $database->lastInsertId();

test表有一个自动增量列id和一个 varchar 列test。我正在使用 WAMP 运行 PHP 和 mysql。

对页面的每个请求都会插入两个具有不同值的条目(来自rand()调用)。仅回显第一个插入 ID。对于 Chrome、Firefox 和 IE,此行为相同。

这是由重写规则引起的:

RewriteEngine on
RewriteRule .* index.php

我假设有一个像 robots.txt 或 favicon.ico 这样的文件是透明请求的。

4

2 回答 2

2

您是否有任何可以重定向到 index.php 的重写/错误文档规则?可能是页面/浏览器试图加载不同的资源(网站图标等)被重定向到索引吗?

于 2011-02-15T19:18:11.320 回答
1

您应该使用表单令牌/随机数来防止这种情况和回复攻击。

http://www.phpro.org/tutorials/Preventing-Multiple-Submits.html

于 2011-02-15T19:20:55.987 回答