Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
New getip function
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Support

2023-05-21 18:40:07
Been having invalid IPV6 addresses on and off for a little while, so this seems to resolve that and updates the IPs correctly, and some filtering on the IPV4 compatible prefix. Takes care of proxies as the original, and lets you convert the IPV4 address to a compatible IPV6 address.


function getip($convertToIPv6 = false)
{
   $trustedHeaders = [
       'HTTP_CLIENT_IP',
       'HTTP_X_FORWARDED_FOR',
       'HTTP_X_FORWARDED',
       'HTTP_X_CLUSTER_CLIENT_IP',
       'HTTP_FORWARDED_FOR',
       'HTTP_FORWARDED',
       'HTTP_CF_CONNECTING_IP',
       'REMOTE_ADDR'
   ];

   $ip = '';
   foreach ($trustedHeaders as $header) {
       if (!empty($_SERVER[$header])) {
           $ip = $_SERVER[$header];
           break;
       }
   }

   if (empty($ip)) {
       $ip = $_SERVER['REMOTE_ADDR'];
   }

   if (strpos($ip, ',') !== false) {
       $ip = explode(',', $ip)[0];
   }

   if (strpos($ip, '::ffff:') === 0) {
       $ip = substr($ip, 7);
   }

   $ip = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);

   if ($convertToIPv6 && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
       $ip = '::ffff:' . $ip;
   }

   return $ip;
}
Last edited by STorrents2020 on 2023-05-21 18:59:39
2023-05-21 19:58:27
cool. Thanks for sharing
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2023-05-21 23:29:19
Most welcome!
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728