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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.