Skip to content

Commit

Permalink
fix loading ip information slow problem
Browse files Browse the repository at this point in the history
  • Loading branch information
taoyu65 committed Aug 10, 2017
1 parent e6b356f commit 016d7cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Database/seeds/umi_field_display_add_seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ public function run()
'id' => 80,
'table_id' => 16,
'field' => 'password',
'type' => 'textBox',
'type' => 'bcryptPassword',
'relation_display' => '',
'custom_value' => '',
'display_name' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/Database/seeds/umi_field_display_edit_seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public function run()
'id' => 96,
'table_id' => 16,
'field' => 'password',
'type' => 'textBox',
'type' => 'bcryptPassword',
'relation_display' => '',
'custom_value' => '',
'display_name' => '',
Expand Down
23 changes: 17 additions & 6 deletions src/Http/Controllers/dashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use YM\Models\User;

Expand Down Expand Up @@ -62,12 +63,12 @@ public function dashboard(Request $request)
if (Auth::attempt(['name' => $userName, 'password' => $password])) {

#######################save ip information#######################
$ip = $_SERVER['REMOTE_ADDR'];
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
if($query && $query['status'] == 'success') {
$country = $query['country'];
$region = $query['region'];
$city = $query['city'];
$ip = $_SERVER['REMOTE_ADDR'];//'98.176.248.193';//
$query = json_decode($this->curl_file_get_contents('http://ip-api.com/json/'.$ip));
if($query && $query->status == 'success') {
$country = $query->country;
$region = $query->region;
$city = $query->city;
$add = DB::table('ip_info')->insert([
'user_name' => $userName,
'ip' => $ip,
Expand Down Expand Up @@ -105,4 +106,14 @@ public function getRefresh()
Cache::flush();
return redirect($url);
}

public function curl_file_get_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
}

0 comments on commit 016d7cd

Please sign in to comment.