基于php的昌吉市野生动物园网站-计算机毕业设计源码+LW文档


野生动物园介绍、动物园门票信息、预定付款、动物园动物信息、动物画廊、园区餐饮、新闻公告、交流讨论、客服。
后台:信息的管理、动物统计、餐饮统计、会员统计。


开发语言:PHP
框架:原生php/thinkphp5
服务器:Apache
数据库:mysql 5.7(一定要5.7版本)
数据库工具:Navicat 11
运行软件:小皮phpStudy
浏览器:谷歌浏览器

源码:
   /**
     * 登录接口
     * POST
     * */
    public function login(){
        $username = isset($_REQUEST['username'])?$_REQUEST['username']:"";
        $password = isset($_REQUEST['password'])?$_REQUEST['password']:"";
        $sql = "select * from `users` where username = '".$username."' and password = '".$password."'";
        $result = table_sql($sql);
        if ($result->num_rows > 0) {
            // 输出数据
            while($row = $result->fetch_assoc()) {
                $token_array = [
                    "iat" => time(), //签发时间
                    "exp" => time()+7200, //token 过期时间
                    'tablename'=> 'users',//表名
                    'isAdmin' => 1,
                    'id' => $row["id"],
                    "success" => $row,//记录的uid的信息,如果有其它信息,可以再添加数组的键值对
                ];
                $tokens = base64_encode(json_encode($token_array));
                $data = ['code' => 0, 'token' => $tokens];
                exit(json_encode($data));
            }
        } else {
            exit(json_encode(['code'=>500,'msg'=>"账号或密码错误"]));
        }
    }
    /**
     * 退出
     * post
     */
    public function logout(){
        $token = $this->token();
        unset($token);
        exit(json_encode(['code'=>0,'msg'=>'退出成功']));
    }
    /**
     * 获取session
     */
    public function session(){
        $token = $this->token();
        $data = json_decode(base64_decode($token),true);
        $arrayData = $data['success'];
        $sql = "select * from `users` where username = '".$arrayData['username']."'";
        $result = table_sql($sql);
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                exit(json_encode(['code'=>0,'data'=>$row]));
            }
        }
        exit(json_encode(['code'=>0,'data'=>$arrayData]));
    }
    /**
     * 找回密码 重置为123456
     **/
    public function resetPass(){
        $username = input('post.username');
        $counts = "select * from `users` where username = '".$username."'";
        $cotte = table_sql($counts);
        if($cotte->num_rows<1){
            exit(json_encode(['code'=>500,'msg'=>"用户名错误。"]));
        }
        $sql = "update users set password = '123456' where username = '".$username."'";
        $result = table_sql($sql);
        if($result) exit(json_encode(['code'=>500,'msg'=>"重置密码错误。"]));
        exit(json_encode(['code'=>0,'msg'=>"密码已重置为:123456"]));
    }
    /**
     * 分页,列表
     * get
     */
    public function page(){
        $token = $this->token();
        $tokens = json_decode(base64_decode($token),true);
        if (!isset($tokens['id']) || empty($tokens['id'])) exit(json_encode(['code'=>403,'msg'=>"你还没有登录。"]));
        $userid = $tokens['id'];
        $page = isset($_REQUEST['page'])?$_REQUEST['page']:"1";
        $limt = isset($_REQUEST['limit'])?$_REQUEST['limit']:"10";
        $sort = isset($_REQUEST['sort'])?$_REQUEST['sort']:"id";
        $order = isset($_REQUEST['order'])?$_REQUEST['order']:"asc";
        $where = "";//查询条件
        $sql = "select * from `users`".$where;
        $count = table_sql($sql);
        if ($count->num_rows < 1){
            $numberCount = 1;
        }else{
            $numberCount = $count->num_rows;
        }
        $page_count = ceil($numberCount/$limt);//页数
        $startCount = ($page-1)*10;
        $lists = "select * from `users` ".$where." order by ".$sort." ".$order." limit ".$startCount.",".$limt;
        $result = table_sql($lists);
        $arrayData = array();
        if ($result->num_rows > 0) {
            while ($datas = $result->fetch_assoc()){
                array_push($arrayData,$datas);
            }
        }
        exit(json_encode([
            'code'=>0,
            'data' => [
                "total" => $count,
                "pageSize" => $limt,
                "totalPage" => $page_count,
                "currPage" => $page,
                "list" => $arrayData
            ]
        ]));
    }
 

  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值