You want to display different content on the website based on different IP address segments. Currently, ipv4 address segments are restricted. However, some clients access ipv4 addresses, and the limitations are useless. So I would like to ask whether it is possible to obtain only ipv4 code through php. The current ph... is used to display different content on the website based on different IP address segments. Currently, ipv4 address segments are restricted. However, some clients access ipv4 addresses, and the limitations are useless. So I would like to ask whether it is possible to obtain only ipv4 code through php.
The php code used to obtain the ip address is as follows:
function check_ip($str) { return preg_match('/""A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))"".){3}(([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))""Z/',$str)>0; } function getIP($isHeader=false) { if($isHeader) { if (isset($_SERVER['HTTP_CLIENT_IP']) && check_ip($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && check_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } } if (isset($_SERVER['REMOTE_ADDR']) && check_ip($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } else { return 'unknown'; } }
Reply content:
You want to display different content on the website based on different IP address segments. Currently, ipv4 address segments are restricted. However, some clients access ipv4 addresses, and the limitations are useless. So I would like to ask whether it is possible to obtain only ipv4 code through php.
The php code used to obtain the ip address is as follows:
function check_ip($str) { return preg_match('/""A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))"".){3}(([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))""Z/',$str)>0; } function getIP($isHeader=false) { if($isHeader) { if (isset($_SERVER['HTTP_CLIENT_IP']) && check_ip($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && check_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } } if (isset($_SERVER['REMOTE_ADDR']) && check_ip($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } else { return 'unknown'; } }