Block users using their ip addresses in php -
actually have no practical experience using php
other in locally hosted server. following video tutorial learn php
, , there code block specific ip
web site. thing want know here if works users have dynamic ip addresses or not? and, proper way block user? i'm glad if can explain more practical side of blocking users. thank you!
<?php $http_client_ip = $_server['http_client_ip']; $http_x_forwarded_for = $server['http_x_forwarded_for']; $remote_address = $server['remote_addr']; if (!empty($http_client_ip)){ $ip_address = $http_client_ip; } elseif (!empty($http_x_forwarded_for)) { $ip_address = $http_x_forwarded_for; } else { $ip_address = $remote_address; } //block list contains ips should blocked. foreach ($block_list $block) { if ($block == $ip_address){ die(); } } ?>
visitors can restricted accessing site using ip deny manager in cpanel or adding allow or deny code in .htaccess file. syntax follows:
allows ip 122.102.1.2 access website. allow 122.102.1.2 denys ip 25.122.6.3 access website. deny 25.122.6.3
both combined as,
order deny,allow deny allow 203.25.45.2 deny unwanted-domain.com
Comments
Post a Comment