Snippet · Mecha CMS

Code snippet collection for developers.

Grab User’s Comment IP and UA

Author: Taufik Nurrohman · 348 Views

Tweet

Store user’s IP and user’s UA string on every comment creation event.

Requires comment extension.

Hook::set('on.comment.set', function() {
    $folder = Path::F($file);
    if ($s = Get::ip()) File::write($s)->saveTo($folder . DS . 'ip.data', 0600);
    if ($s = Get::ua()) File::write($s)->saveTo($folder . DS . 'ua.data', 0600);
});

Then, you can call the stored comment IP and UA this way:

<?php echo $comment->ip; ?>
<?php echo $comment->ua; ?>

0 Comments

No comments yet.