update
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use App\model\Ip2locationDb11Model;
|
||||
use itbdw\Ip\IpLocation;
|
||||
use support\Db;
|
||||
use support\Request;
|
||||
|
||||
class Index
|
||||
@@ -21,4 +23,30 @@ class Index
|
||||
|
||||
return json(['ip' => $ip, 'location' => $location]);
|
||||
}
|
||||
|
||||
public function location(Request $request, $checkIp = null)
|
||||
{
|
||||
$ip = $request->getRealIp();
|
||||
|
||||
if ($checkIp) {
|
||||
$ip = gethostbyname($checkIp);
|
||||
}
|
||||
|
||||
$ipNum = ip2long($ip);
|
||||
|
||||
|
||||
$record = Ip2locationDb11Model::query()->where(
|
||||
'ip_from', '<=', $ipNum
|
||||
)->where(
|
||||
'ip_to', '>=', $ipNum
|
||||
)->first();
|
||||
|
||||
if ($record) {
|
||||
$record = $record->toArray();
|
||||
} else {
|
||||
$record = [];
|
||||
}
|
||||
|
||||
return json(['ip' => $ip, 'record' => $record]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author jhx
|
||||
* @date 2022/7/6 14:53
|
||||
*/
|
||||
|
||||
namespace App\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class Ip2locationDb11Model extends Model
|
||||
{
|
||||
public $timestamps = FALSE;
|
||||
|
||||
protected $primaryKey = 'ip_from';
|
||||
|
||||
protected $table = 'ip2location_db11';
|
||||
}
|
||||
Reference in New Issue
Block a user