from PHP, how I can detect visitior using IPv6 ?

cPanelChris

Moderator
Staff member
Feb 16, 2020
38
4
8
Houston, TX
cPanel Access Level
Root Administrator
Hello @000 ,

Something like the following should work to check what protocol an IP is.

PHP:
<?php
$ip = "255.255.255.255";
//$ip = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329";

if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    echo "IPv4\n";
} else if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
    echo "IPv6\n";
} else {
    echo "Invalid IP\n";
}
 

000

Well-Known Member
Jun 3, 2008
270
12
68
Many thanks Chrish :)

Then if we have RECORD in data base as
PHP:
column_ip_client = varchar 15
that is WRONG ?
Any day, any hour our web can go visited by
Code:
FILTER_FLAG_IPV6
?
 

cPanelChris

Moderator
Staff member
Feb 16, 2020
38
4
8
Houston, TX
cPanel Access Level
Root Administrator