qa-ifish7/web/Application/Home/Controller/BaseController.class.php

37 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller
{
private $loginStatus=1;//1为登录正常0为登录异常
public $user_id;
public $openid;
function _initialize() {
//api接口相关设置
C("SHOW_PAGE_TRACE",false);//强制关闭调试器
header("Access-Control-Allow-Origin:*");//允许ajax远程跨域
header('Access-Control-Allow-Headers:x-requested-with,content-type,user_id,openid');
}
public function __construct(){
parent::__construct();
//校验用户登录信息
$this->checkLogin();
}
function checkLogin(){
$this->user_id=$_SERVER['HTTP_USER_ID'];
if(!$this->user_id){
$loginStatus = 0;
}
$this->openid = $_SERVER['HTTP_OPENID'];
if(!$this->openid){
$loginStatus = 0;
}
header('loginStatus:'.$this->loginStatus);
//error方法一定要放到header下而否则客户端无法收到header中的loginStatus,newToken字段
if(!$this->loginStatus ){
$this->error('未登录');
}
}
}