我对 PHP 很陌生,当我打开此页面查看文档时,我似乎遇到了插入语句执行两次的问题。该文档显示没有错误。在数据库中,第二次插入是 1 秒后。它仅在 google chrome 和此页面上发生。IE没有问题,我没有firefox可以检查。
view_document.php
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/../includes/core.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/../includes/connect.php');
$webusername = $_SESSION['webname'];
if (isset($_GET['document']))
{
$ainumber = (int) $_GET['document'];
if (!ctype_digit($_GET['document']) || !preg_match('~^[0-9]+$~', $_GET['document']) || !is_numeric($_GET['document']))
{
$_SESSION = array();
session_destroy();
header('Location: login.php');
}
else
{
$stmt = $connect->prepare("SELECT s_filename, s_reference FROM dmsmain WHERE s_ainumber = ?") or die(mysqli_error());
$stmt->bind_param('s', $ainumber);
$stmt->execute();
$stmt->bind_result($filename, $reference);
$stmt->fetch();
$stmt->close();
$file = $_SERVER['DOCUMENT_ROOT'] . '/../dms/files/' . $filename . '.pdf';
if (file_exists($file))
{
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
readfile($file);
$stmt = $connect->prepare("INSERT INTO dmslog (s_reference, s_userid, s_lastactivity, s_actiontype) VALUES (?, ?, ?, ?)") or die(mysqli_error());
date_default_timezone_set('Africa/Johannesburg');
$date = date('Y-m-d H:i:s');
$actiontype = 'DL';
$stmt->bind_param('ssss', $reference, $webusername, $date, $actiontype);
$stmt->execute();
$stmt->close();
}
else
{
$missing = "<b>File not found</b>";
}
exit(0); // Correct Place?
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../CSS/dms.css" rel="stylesheet" type="text/css" />
<link href="../favicon.ico" rel="icon" type="image/x-icon" />
<title>Denso Document Manager - View Document</title>
</head>
<body>
<div id="container">
<div id="header">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="28%"><img src="../images/Logo.gif"/></td>
<td width="43%"><h2 style="color:#666" align="left">Denso SA Document Management System</h2></td>
<td width="3%"> </td>
<td width="25%" align="right"><?php echo "Welcome $webusername <input class=\"look\" type=\"button\" onclick=\"parent.location='logout.php'\" value=' Logout ' />" ?></td>
</tr>
</table>
<br />
<table bgcolor="#6699CC" height="30px" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20%" align="center"><p style="color:#FFF"><b>Document Search</b></p></td>
<td width="20%" align="center"><p style="color:#FFF"><b>Add Document</b></p></td>
</tr>
</table>
</div>
<div id="content">
<?php echo $missing; ?>
<br />
<br />
</div>
<div id="footer">
<table width="100%" bgcolor="#6699CC">
<tr>
<td height="25px"></td>
</tr>
</table>
<table width="100%" bgcolor="#000000">
<tr>
<td height="25px"></td>
</tr>
</table>
</div>
</div>
</body>
</html>
我假设的 HTTP 访问记录
[15/Nov/2012:10:14:32 +0200] "POST /dms/search.php HTTP/1.1" 200 5783 "http://www.denso.co.za/dms/search.php" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
[15/Nov/2012:10:14:33 +0200] "GET /favicon.ico HTTP/1.1" 404 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
[15/Nov/2012:10:14:34 +0200] "GET /dms/view_document.php?document=8 HTTP/1.1" 200 2965 "http://www.denso.co.za/dms/search.php" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
[15/Nov/2012:10:14:35 +0200] "GET /favicon.ico HTTP/1.1" 404 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
我检查了我的<img src=''>
链接,我没有发现它们有问题。
记录表明有一个 favicon.ico 请求,所以我创建了一个空白 favicon 并将其放在我的 public_html 文件夹中,并将其链接到页面中,如下所示<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon" />
不幸的是,这不起作用,因为该语句仍然执行两次。我不确定这是否是网站图标问题,因为我的上传页面使用插入查询并且它执行一次。
如果有人能告诉我哪里出错或指出正确的方向,我将不胜感激