Add exams from exam58 to exam98
This commit is contained in:
13
exam65/VisitorsIP.php
Normal file
13
exam65/VisitorsIP.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
//How to get visitor ip address
|
||||
require 'config.inc.php';
|
||||
|
||||
foreach($ip_blocked as $ip){
|
||||
if($ip == $ip_address){
|
||||
die('Your ip address, ' . $ip_address . ' has been blocked');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h1>Welcome !</h1>
|
||||
17
exam65/VisitorsIP2.php
Normal file
17
exam65/VisitorsIP2.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// Better way to get visitors IP
|
||||
|
||||
$http_client_ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
$http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$remote_addr = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
if(!empty($http_client_ip)){
|
||||
$ip_address = $http_client_ip;
|
||||
} else if(!empty($http_x_forwarded_for)){
|
||||
$ip_address = $http_x_forwarded_for;
|
||||
} else {
|
||||
$ip_address = $remote_addr;
|
||||
}
|
||||
|
||||
echo $ip_address;
|
||||
?>
|
||||
8
exam65/config.inc.php
Normal file
8
exam65/config.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$ip_address = $_SERVER['REMOTE_ADDR'];
|
||||
$ip_blocked = array('127.0.0.1', '100.100.100.100');
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user