Display IP Address for all comments in Drupal 6.16 - 6.20

By BXTra |

I have searched many places how to display user IP for each comment. There is no complete answer in any topics that I found. Therefore, I just tried each part of each information until I know how to do it. Below is what I did to make it work:

1. Search file "comment.module" here - > "modules/comment/comment.module"

1.1. Add c.hostname into query line number 939

FROM

$query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';

TO

$query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, c.hostname, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';

1.2 Add c.hostname into query line number 960

FROM

$query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';

TO

$query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, c.hostname, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';

2. Now, you should be able to use code <?php print $comment->hostname; ?> to display IP address. This command is to be use in file comment.tpl.php. (Theme Directory) Below is an example how to use it :

<div class="submitted">
     <?php print $submitted; ?>
     <?php print t('(IP Address : ' . $comment->hostname . ')'); ?>
</div>

Optional : If you want to display IP Address only for anonymous user. User the code below :

  <div class="submitted">
     <?php print $submitted; ?>
    <?php if (($comment->uid)==0): ?>
    	<?php print t('(IP Address : ' . $comment->hostname . ')'); ?>
    <?php endif; ?>
  </div>

 

More Info :
- Provide {comment}.hostname in comment_render() ( http://drupal.org/node/514928 )
- IP address in comment ( http://drupal.org/node/695112 )

Add new comment

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.