Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP在数据库中保存IP和其他访问者信息_Php_Sql_Database_Ip - Fatal编程技术网

使用PHP在数据库中保存IP和其他访问者信息

使用PHP在数据库中保存IP和其他访问者信息,php,sql,database,ip,Php,Sql,Database,Ip,我试图在数据库中存储访问者信息。如果表不存在,我需要创建一个表,然后存储信息。但是信息没有被存储,我需要代码方面的帮助。 代码-- 仍不支持该建议(此处截图) “phpadmin”您的insert语句引用了一个名为“ref”的列,该列不是您正在创建的表的一部分 请停止使用古老的mysql_*函数编写新代码。它们不再得到维护,社区已开始恢复。相反,您应该学习准备好的语句,并使用或。如果你想学习。 // visitor information $ip = addslashes((getenv(HTT

我试图在数据库中存储访问者信息。如果表不存在,我需要创建一个表,然后存储信息。但是信息没有被存储,我需要代码方面的帮助。 代码--

仍不支持该建议(此处截图)
“phpadmin”

您的insert语句引用了一个名为“ref”的列,该列不是您正在创建的表的一部分

请停止使用古老的mysql_*函数编写新代码。它们不再得到维护,社区已开始恢复。相反,您应该学习准备好的语句,并使用或。如果你想学习。
// visitor information
$ip = addslashes((getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR));
$visitorReferrer = addslashes(( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'Referrer undetectable.');
$visitorBrowser = addslashes(( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'Browser undetectable.');

// connect database
$con = mysql_connect("localhost","UNAME","PASS");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

// Create table
mysql_select_db("DBNAME", $con);
$sql = "CREATE TABLE IF NOT EXISTS `logs` (
 `id` int(11) unsigned NOT NULL auto_increment,
 `ip` varchar(255) NOT NULL default '',
 `brow` varchar(255) NOT NULL default '',
 `times` varchar(500) NOT NULL default '',
  PRIMARY KEY  (`id`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8";

// query
mysql_query($sql,$con);
mysql_close($con);

mysql_query("INSERT INTO 'logs' (ip, ref, brow, times ) VALUES('{$ip}', '{$visitorReferrer}', '{$visitorBrowser}', now())");
mysql_close($con);

// image header to browser.
header("Content-Type: image/jpeg");

// create image and allocate colors...
$im = @imagecreate(110, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);

// IP text
imagestring($im, 1, 5, 5,  "Hello $ip !", $text_color);
imagepng($im);
imagedestroy($im);