Action: GetIP
| Current version: Credits: |
{{getip}}
/action/getip.php
<?php
// determine IP
$tpl->ip = $ip = $this->get_user_ip();
// resolve IP and determine host
$tpl->host = gethostbyaddr($ip); /action/template/getip.tpl
[ === main === ]
[ ' ip ' ]<br>
[ ' host ' ]<br>
评论 4240
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.
If the IP is 111.111.111.111, display 111.111.111.*,or 111.111.*.*
This was added only as a snippet
maindefinition 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.Or disable the page cache for guests, which is a rather less good option, it is used primarily for Captcha and form tokens.
The
get_user_ip()function itself already contains a simple anonymize feature if the config settinganonymize_ipis enabled.