diff --git a/app/common/controller/BaseController.php b/app/common/controller/BaseController.php index 0464381..69d12d1 100644 --- a/app/common/controller/BaseController.php +++ b/app/common/controller/BaseController.php @@ -237,7 +237,7 @@ abstract class BaseController protected function showUser() { //1.查询用户 - $user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point')->where('id',Session::get('user_id'))->cache(600)->find(); + $user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point,create_time')->where('id',Session::get('user_id'))->cache(600)->find(); //2.将User变量赋给模板 公共模板nav.html View::assign('user',$user); } diff --git a/app/common/model/User.php b/app/common/model/User.php index 6718e01..7695aa7 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -55,23 +55,24 @@ class User extends Model Session::set('user_id',$user['id']); Session::set('user_name',$user['name']); $ip = request()->ip(); +/* $url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN'; //$url = 'http://ip-api.com/json/?lang=zh-CN'; - $add = Api::urls($url); + $add = Api::urlGet($url); if($add->status == 'success'){ $city = $add->city; } else { $city ='未知'; } - +*/ Db::name('user')->where('id',$user['id'])->update( [ - 'city' => $city, + //'city' => $city, 'last_login_ip' => $ip, 'last_login_time' => time() ] ); - Log::channel('login')->info('login:{user} {ip}:{city}',['user'=>$user['name'],'ip'=>$ip,'city'=>$city]); + Log::channel('login')->info('login:{user} {ip}',['user'=>$user['name'],'ip'=>$ip]); //查询结果1表示有用户,用户名密码正确 return 1; diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 82d69f7..6712e01 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -254,11 +254,11 @@ class Article extends BaseController { $file = request()->file('file'); try { - validate(['file'=>'fileSize:2048|fileExt:jpg,png,gif']) + validate(['file'=>'fileSize:1024000|fileExt:jpg,png,gif']) ->check(['file'=>$file]); $savename = \think\facade\Filesystem::disk('public')->putFile('article_pic',$file); } catch (ValidateException $e) { - echo $e->getMessage(); + return json(['status'=>-1,'msg'=>$e->getMessage()]); } $upload = Config::get('filesystem.disks.public.url'); diff --git a/app/index/controller/User.php b/app/index/controller/User.php index f547bb0..b2f1282 100644 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -94,11 +94,11 @@ class User extends BaseController { $file = request()->file('file'); try { - validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg']) - ->check(array($file)); + validate(['file'=>'filesize:204800|fileExt:jpg,png,gif']) + ->check(['file'=>$file]); $savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file); } catch (think\exception\ValidateException $e) { - echo $e->getMessage(); + return json(['status'=>-1,'msg'=>$e->getMessage()]); } $upload = Config::get('filesystem.disks.public.url'); if($savename){ diff --git a/extend/taoler/com/Api.php b/extend/taoler/com/Api.php index fd2d68a..f380f4b 100644 --- a/extend/taoler/com/Api.php +++ b/extend/taoler/com/Api.php @@ -4,7 +4,7 @@ namespace taoler\com; class Api { - public static function urls($url) + public static function urlPost($url, $data) { if($url == ''){ return json(['code'=>-1,'msg'=>'800']); @@ -14,6 +14,7 @@ class Api curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch,CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $data = curl_exec($ch); $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE); curl_close($ch); @@ -23,4 +24,44 @@ class Api return json(['code'=>-1,'msg'=>'Զ̷ʧ']); } } + + public static function urlGet($url) + { + $ch =curl_init (); + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); + //curl_setopt($ch, CURLOPT_HEADER, 0); //ʱὫͷļϢΪ Ϊ1ʾϢͷ,Ϊ0ʾ + curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1) ; // CURLOPT_RETURNTRANSFER ʱ򽫻ȡݷ + $data = curl_exec($ch); + $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE); + curl_close($ch); + if($httpCode == '200'){ + return json_decode($data); + } else { + return json(['code'=>-1,'msg'=>'Զ̷ʧ']); + } + } + + public static function get_real_ip() + { + static $realip; + if (isset($_SERVER)) { + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $realip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else if (isset($_SERVER['HTTP_CLIENT_IP'])) { + $realip = $_SERVER['HTTP_CLIENT_IP']; + } else { + $realip = $_SERVER['REMOTE_ADDR']; + } + } else { + if (getenv('HTTP_X_FORWARDED_FOR')) { + $realip = getenv('HTTP_X_FORWARDED_FOR'); + } else if (getenv('HTTP_CLIENT_IP')) { + $realip = getenv('HTTP_CLIENT_IP'); + } else { + $realip = getenv('REMOTE_ADDR'); + } + } + return $realip; + } } \ No newline at end of file diff --git a/public/.htaccess b/public/.htaccess index f6dffab..d142ad7 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -2,9 +2,6 @@ Options +FollowSymlinks -Multiviews RewriteEngine On FileETag MTime Size - RewriteBase / - RewriteCond %{SERVER_PORT} !^443$ - RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f