• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Hide Admin / Moderator IP Address

Hide Admin / Moderator IP Address 1.0.1

No permission to download
Hide Admin / Moderator IP Address
Compatible XF 1.x versions
1.5
License
Creative Commons license
No download is needed :)
___________________

This is how to hide IP address of Admin / Moderator's / Any other user that you pick (as long as you have defined specific user ID).
Well, it is not "hiding", actually it is overwriting their IP data in the database with a fake IP.

This modification needs file editing to core Xenforo file, which is located in :
Code:
/library/Xenforo/Model/Ip.php
Please make a backup copy of that file before proceeding ;)

But please note :
  • The file change will be overwriten if you upload new Xenforo files while upgrading the board.
  • Even when you undo the file edit, the fake IP data will not be replaced with the real IP. This is one-way replacement.
  • This mod does not replace IP data which was recorded before this mod is activated.
    So if you want to replace your old IP data, you have to run a SQL query such as this :
    Code:
    UPDATE xf_ip SET ip =  'cccc' WHERE user_id =1
    (cccc means 99.99.99.99, if you wonder)
~~~~~~~~~~~
First, you have to decide which fake IP do you want to use. 99.99.99.99, or 88.88.88.88 or something else.
Please note : i noticed that some IP such as 1.1.1.1 won't work, which means NULL will be recorded as the IP.
I don't know why that happens.
I pick 99.99.99.99 :D

Second, here goes the file editing, for example you want to set user ID 1 to have IP 99.99.99.99

Search for this
PHP:
    public function logIp($userId, $contentType, $contentId, $action, $ipAddress = null, $date = null)
    {
        $ipAddress = XenForo_Helper_Ip::getBinaryIp(null, $ipAddress);
        if (!$ipAddress)
        {
            return 0;
        }

        if ($date === null)
        {
            $date = XenForo_Application::$time;
        }

        $this->_getDb()->insert('xf_ip', array(
            'user_id' => $userId,
            'content_type' => $contentType,
            'content_id' => $contentId,
            'action' => $action,
            'ip' => $ipAddress,
            'log_date' => max(0, $date)
        ));

        return $this->_getDb()->lastInsertId();
    }
Replace with this :
PHP:
    public function logIp($userId, $contentType, $contentId, $action, $ipAddress = null, $date = null)
    {
        if (1 == $userId) {/* Semprot modification */
            $ipAddress = '99.99.99.99';
        }

        $ipAddress = XenForo_Helper_Ip::getBinaryIp(null, $ipAddress);
        if (!$ipAddress)
        {
            return 0;
        }

        if ($date === null)
        {
            $date = XenForo_Application::$time;
        }

        $this->_getDb()->insert('xf_ip', array(
            'user_id' => $userId,
            'content_type' => $contentType,
            'content_id' => $contentId,
            'action' => $action,
            'ip' => $ipAddress,
            'log_date' => max(0, $date)
        ));

        return $this->_getDb()->lastInsertId();
    }
If you want to hide IP of some user IDs (1, 22, 192, 391) :
Replace with this :
PHP:
    public function logIp($userId, $contentType, $contentId, $action, $ipAddress = null, $date = null)
    {
        if (in_array($userId, array(1, 22, 192, 391))) {/* Semprot modification */
            $ipAddress = '99.99.99.99';
        }

        $ipAddress = XenForo_Helper_Ip::getBinaryIp(null, $ipAddress);
        if (!$ipAddress)
        {
            return 0;
        }

        if ($date === null)
        {
            $date = XenForo_Application::$time;
        }

        $this->_getDb()->insert('xf_ip', array(
            'user_id' => $userId,
            'content_type' => $contentType,
            'content_id' => $contentId,
            'action' => $action,
            'ip' => $ipAddress,
            'log_date' => max(0, $date)
        ));

        return $this->_getDb()->lastInsertId();
    }
Last is hiding IP in online list (thanks to @Ibrahim H for reminding me :D)
We only need to do template editing.

Template name : online_list

Find :
PHP:
<a href="{xen:if '{$user.user_id}', {xen:link online/user-ip, $user}, {xen:link online/guest-ip, '', 'ip={$user.ipHex}'}}" class="OverlayTrigger ip"><span>{xen:helper ip, $user.ip}</span></a>
Change into :
PHP:
<xen:if is="in_array({$user.user_id}, array(1))">
    Hidden
<xen:else />
    <a href="{xen:if '{$user.user_id}', {xen:link online/user-ip, $user}, {xen:link online/guest-ip, '', 'ip={$user.ipHex}'}}" class="OverlayTrigger ip"><span>{xen:helper ip, $user.ip}</span></a>
</xen:if>
  • Tested on Xenforo 1.5.13
  • This modification is free, and you can use this code in your add on for free, just PM me first ;)
Likes: CNK
Author
semprot
Downloads
42
First release
Last update
Rating
5.00 star(s) 1 ratings

More resources from semprot

Latest updates

  1. Hide IP in Online List

    To hide IP in online list, you can do template modification.

Latest reviews

Nice and simple! It works very nice, but hope to have an upgrade version with better way for running cron jobs.
semprot
semprot
Can you explain what task would you with cron job? :)