This is a comment on Action: GetIP, posted by WikiAdmin at 05/22/2022 07:08
View source for This was added only as a snippet
I added the ##main## definition declaration to the example above, so it will work out of the box.
You probably want wrap it in ##$this->get_user()## condition so it won't be cached.
%%(php)
<?php
if ($this->get_user())
{
$dot = strripos($ip, '.');
$tpl->ip = substr($ip, 0, $dot) . '.*';
}
%%
Or disable the page cache for guests, which is a rather less good option, it is used primarily for Captcha and form tokens.
%%(php)
<?php
// disable server cache for page
$this->http->no_cache(false);
%%
The ##get_user_ip()## function itself already contains a simple anonymize feature if the config setting ##anonymize_ip## is enabled.
%%(php)
<?php
function get_user_ip()
{
if ($this->db->anonymize_ip)
{
return '0.0.0.0';
}
else
{
return $this->http->ip;
}
}
%%