Exemplo n.º 1
0
 /**
  * 禁止ip
  *
  * @return void
  */
 public function banIp($ip)
 {
     if (!($r = @explode('.', $ip))) {
         return;
     }
     list($ip_section1, $ip_section2, $ip_section3, $ip_section4) = $r;
     $now = time();
     $valid_time = $now + 43200;
     require "function/cook.php";
     $from_address = ipToAddress($ip);
     if ($this->db()->table('banip')->where("ip_section1=%d AND ip_section2=%d AND ip_section3=%d AND ip_section4=%d", $ip_section1, $ip_section2, $ip_section3, $ip_section4)->count()) {
         $this->db()->table('banip')->where("ip_section1=%d AND ip_section2=%d AND ip_section3=%d AND ip_section4=%d", $ip_section1, $ip_section2, $ip_section3, $ip_section4)->update("ban_time = %d,valid_time = %d,attack_amount=attack_amount+1,ip_address = '%s'", $now, $valid_time, $from_address);
     } else {
         $this->db()->table('banip')->insert(['ban_time' => $now, 'valid_time' => $valid_time, 'attack_amount' => 0, 'ip_address' => $from_address, 'ip_section1' => $ip_section1, 'ip_section2' => $ip_section2, 'ip_section3' => $ip_section3, 'ip_section4' => $ip_section4]);
     }
 }
	<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
    
	
<?php 
        require_once 'get_geo_location.php';
        ?>

<?php 
    }
}
?>

	
<?php 
if ($user_lat == '' && $user_long == '' && $user_city == '' && $user_region == '' && $user_country == '' && $user_address == '') {
    $parsedJson = ipToAddress('203.153.223.84');
    $user_lat = $parsedJson->latitude;
    $user_long = $parsedJson->longitude;
    $user_city = $parsedJson->city;
    $user_region = $parsedJson->region_name;
    $user_country = $parsedJson->country_name;
    $user_address = $user_city . ', ' . $user_region . ', ' . $user_country;
}
function ipToAddress($ip)
{
    $pageContent = file_get_contents('http://freegeoip.net/json/' . $ip);
    return json_decode($pageContent);
}
?>
 
Exemplo n.º 3
0
 }
 //临时关闭
 if ($company['closed']) {
     apiOutput(NO, "service temporarily unavailable");
 }
 //统计请求量
 X::module('company')->statisticsRequest($company['company_id']);
 $now = time();
 require 'function/post.php';
 list($tutu, $process_time) = searchEngine(['content' => $post->title . $post->content, 'if_spam' => $post->if_spam], true);
 if (!$tutu) {
     apiOutput(NO, "search service is not available");
 }
 $tutu = toArray($tutu);
 require "function/cook.php";
 $from_address = ipToAddress($post->client_ip);
 $tutu['title'] = $post->title;
 $tutu['content'] = $post->content;
 $tutu['posts_time'] = $now;
 $tutu['company_username'] = $company['company_name'];
 $tutu['company_id'] = $company['company_id'];
 $tutu['ip_city'] = $from_address;
 $tutu['process_time'] = $process_time;
 $tutu['ip'] = $post->client_ip;
 //请求日志
 X::module('post')->banLog($tutu);
 //IP是否被拦截
 $ipInfo = X::module('post')->whetherInBanip($post->client_ip);
 if ($ipInfo && $tutu['hit'] || $ipInfo && $ipInfo['valid_time'] > $now) {
     if ($tutu['hit']) {
         //看是否内容再次是非法,是就增加IP拦截时效