所以,我得到了这段代码:
<?php
$servername = "localhost";
$username = "**";
$password = "**";
$dbname = "TestDB";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully<br>";
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO testdata (id,address,count) VALUES (DEFAULT,'$ip',1) ON DUPLICATE KEY UPDATE count=count+1";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully<br>";
} else {
echo "Error: " ;
}
$conn->close();
?>
使用此代码可以保存客户的IP地址,并且每次返回网站时都应该将计数增加1。当我直接访问database.php时,它在每个浏览器中都应该工作,但是当我通过index.html页面调用php文件时,它会在Mozilla中重复两次(大部分时间,并非总是如此),其他浏览器没有问题,html文件中的代码:
<img style="display: none;" src="http://servername/database.php?">
任何人都知道为什么?请帮忙,我真的被困在这里