Jump to content

Tracking IP address


ryanwood4

Recommended Posts

Hiya,

 

I'm trying to track the IP address of users leaving comments, however I am struggling to integrate it into the code (below), several attempts have failed.

 

      $_POST['comment'] = str_replace("'", "\'", $_POST['comment']);
      $sql="INSERT INTO articlecomments (articleID, posterNickname, email, comment)
      VALUES ('$_GET[id]','$_POST[name]','$_POST[email]','$_POST[comment]')";
      mysql_query($sql);

 

Any help is, as always, greatly appreciated.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/205062-tracking-ip-address/
Share on other sites

here's a safer way to do what you are wanting to do:

<?php
function clearup($input){
if (is_array($input)){
	foreach ($input as $key=>$val){
		$out[$key] = mysql_real_escape_string($val);
	}
}
else{
	$out = mysql_real_escape_string($input);
}
return $out;
}
$post = clearup($_POST);
$get = clearup($_GET);
$ip = $_SERVER['REMOTE_ADDR'];
      $sql="INSERT INTO `articlecomments`(`articleID`, `posterNickname`, `email`, `comment`, `ip`) VALUES ('{$get['id']}','{$post['name']}','{$post['email']}','{$post['comment']}', '$ip')";
      mysql_query($sql);
?>

Link to comment
https://forums.phpfreaks.com/topic/205062-tracking-ip-address/#findComment-1073478
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.