构造sql语句然后通过mysql_query将函数返回的值写入数据库
发布网友
发布时间:2022-04-08 11:08
我来回答
共1个回答
热心网友
时间:2022-04-08 12:38
function get_client_ip() {
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'],
$matches)) {
foreach ($matches[0] AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
}
return $ip;
}
$conn=mysql_connect("localhost","root","123412341234");
mysql_select_db("shujuku",$conn);
$query="INSERT INTO ip(`id`,`userip`)VALUES(null,'".get_client_ip()."');";
$result=mysql_query($query);
是不是应该这样写法的啊