Action: GetIP

Current version:



// determine IP
$tpl->ip $ip $this->get_user_ip();
// resolve IP and determine host
$tpl->host gethostbyaddr($ip);


[ === main === ]
[ ' ip ' ]<br>
[ ' host ' ]<br>


  1. 评论 4240

     templatest: no main template found in action/template/getip.tpl

    Add failed.
    I don't understand templates.
    If I can succeed, I want to modify the code to display part of the IP and publish the IP of the page, not that of the visitor.

    $dot = strripos($ip,"."); //查找“.”最后出现的位置
    $hide_ip = substr($ip,0,$dot).".*"; //输出“.”最后出现位置之前的字符串并加上*号
    echo $hide_ip;

    If the IP is, display 111.111.111.*,or 111.111.*.*
  2. 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.

    if ($this->get_user())
    $dot        strripos($ip'.');
    $tpl->ip    substr($ip0$dot) . '.*';

    Or disable the page cache for guests, which is a rather less good option, it is used primarily for Captcha and form tokens.

    // disable server cache for page

    The get_user_ip() function itself already contains a simple anonymize feature if the config setting anonymize_ip is enabled.

    function get_user_ip()
        if (
    • WikiAdmin
    • 22.05.2022 07:08 edited