如何将服务器IP输入mysql表?

时间:2015-06-14 14:22:19

标签: php html mysql

我想创建一个页面,该页面不显示访问过的时间以及访问网页的所有IP地址。

为此,我创建了一个mysql表,在新行中显示新IP,但我无法执行它。

最有可能的错误是将服务器ip输入到表中。这是完整的代码:

<html>
<head>
<title>Delta sys ad task3</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'prabakar';
$dbpass = 'praba1110';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('server_IPs', $conn);
echo mysql_errno($conn) . ": " . mysql_error($conn). "\n";
$counter=1;
$flag=0;
$sql='SELECT * FROM IPs';
$retval = mysql_query( $sql, $conn );
	while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
	{
		if($_SERVER[SERVER_ADDR]==$row['ip'])
			break;
		else
			$flag=1;
	
	}
if($flag==1)
{
	$sql="INSERT INTO IPs VALUES('$_SERVER[SERVER_ADDR]')";
	$retval = mysql_query( $sql, $conn );
}
echo mysql_errno($conn) . ": " . mysql_error($conn). "\n";

$counter++;
print "No of times site visited: $counter

	IP Adresses visited:";
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
	print "$row['ip']";
	
}
mysql_close($conn);
?>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您需要删除额外的引用:

更改

filePath

('$_SERVER['SERVER_ADDR']')