cache
This commit is contained in:
parent
d079f03887
commit
e8e5da04b0
@ -237,7 +237,7 @@ abstract class BaseController
|
|||||||
protected function showUser()
|
protected function showUser()
|
||||||
{
|
{
|
||||||
//1.查询用户
|
//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
|
//2.将User变量赋给模板 公共模板nav.html
|
||||||
View::assign('user',$user);
|
View::assign('user',$user);
|
||||||
}
|
}
|
||||||
|
@ -55,23 +55,24 @@ class User extends Model
|
|||||||
Session::set('user_id',$user['id']);
|
Session::set('user_id',$user['id']);
|
||||||
Session::set('user_name',$user['name']);
|
Session::set('user_name',$user['name']);
|
||||||
$ip = request()->ip();
|
$ip = request()->ip();
|
||||||
|
/*
|
||||||
$url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN';
|
$url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN';
|
||||||
//$url = 'http://ip-api.com/json/?lang=zh-CN';
|
//$url = 'http://ip-api.com/json/?lang=zh-CN';
|
||||||
$add = Api::urls($url);
|
$add = Api::urlGet($url);
|
||||||
if($add->status == 'success'){
|
if($add->status == 'success'){
|
||||||
$city = $add->city;
|
$city = $add->city;
|
||||||
} else {
|
} else {
|
||||||
$city ='未知';
|
$city ='未知';
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Db::name('user')->where('id',$user['id'])->update(
|
Db::name('user')->where('id',$user['id'])->update(
|
||||||
[
|
[
|
||||||
'city' => $city,
|
//'city' => $city,
|
||||||
'last_login_ip' => $ip,
|
'last_login_ip' => $ip,
|
||||||
'last_login_time' => time()
|
'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表示有用户,用户名密码正确
|
//查询结果1表示有用户,用户名密码正确
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -254,11 +254,11 @@ class Article extends BaseController
|
|||||||
{
|
{
|
||||||
$file = request()->file('file');
|
$file = request()->file('file');
|
||||||
try {
|
try {
|
||||||
validate(['file'=>'fileSize:2048|fileExt:jpg,png,gif'])
|
validate(['file'=>'fileSize:1024000|fileExt:jpg,png,gif'])
|
||||||
->check(['file'=>$file]);
|
->check(['file'=>$file]);
|
||||||
$savename = \think\facade\Filesystem::disk('public')->putFile('article_pic',$file);
|
$savename = \think\facade\Filesystem::disk('public')->putFile('article_pic',$file);
|
||||||
} catch (ValidateException $e) {
|
} catch (ValidateException $e) {
|
||||||
echo $e->getMessage();
|
return json(['status'=>-1,'msg'=>$e->getMessage()]);
|
||||||
}
|
}
|
||||||
$upload = Config::get('filesystem.disks.public.url');
|
$upload = Config::get('filesystem.disks.public.url');
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ class User extends BaseController
|
|||||||
{
|
{
|
||||||
$file = request()->file('file');
|
$file = request()->file('file');
|
||||||
try {
|
try {
|
||||||
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
|
validate(['file'=>'filesize:204800|fileExt:jpg,png,gif'])
|
||||||
->check(array($file));
|
->check(['file'=>$file]);
|
||||||
$savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file);
|
$savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file);
|
||||||
} catch (think\exception\ValidateException $e) {
|
} catch (think\exception\ValidateException $e) {
|
||||||
echo $e->getMessage();
|
return json(['status'=>-1,'msg'=>$e->getMessage()]);
|
||||||
}
|
}
|
||||||
$upload = Config::get('filesystem.disks.public.url');
|
$upload = Config::get('filesystem.disks.public.url');
|
||||||
if($savename){
|
if($savename){
|
||||||
|
@ -4,7 +4,7 @@ namespace taoler\com;
|
|||||||
|
|
||||||
class Api
|
class Api
|
||||||
{
|
{
|
||||||
public static function urls($url)
|
public static function urlPost($url, $data)
|
||||||
{
|
{
|
||||||
if($url == ''){
|
if($url == ''){
|
||||||
return json(['code'=>-1,'msg'=>'800']);
|
return json(['code'=>-1,'msg'=>'800']);
|
||||||
@ -14,6 +14,7 @@ class Api
|
|||||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
||||||
curl_setopt($ch,CURLOPT_POST, 1);
|
curl_setopt($ch,CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||||
$data = curl_exec($ch);
|
$data = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
@ -23,4 +24,44 @@ class Api
|
|||||||
return json(['code'=>-1,'msg'=>'远程服务器失败']);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,9 +2,6 @@
|
|||||||
Options +FollowSymlinks -Multiviews
|
Options +FollowSymlinks -Multiviews
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
FileETag MTime Size
|
FileETag MTime Size
|
||||||
RewriteBase /
|
|
||||||
RewriteCond %{SERVER_PORT} !^443$
|
|
||||||
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
|
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
Loading…
x
Reference in New Issue
Block a user