4 Star 9 Fork 5

Gitee 极速下载/qc_classrom

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/qcminecraft/qc_classrom
克隆/下载
index.php 4.34 KB
一键复制 编辑 原始数据 按行查看 历史
<?php
/**
* ___ ____ _
* / _ \ / ___| | __ _ ___ ___ _ __ ___ ___ _ __ ___
*| | | | | | |/ _` / __/ __| '__/ _ \ / _ \| '_ ` _ \
*| |_| | |___| | (_| \__ \__ \ | | (_) | (_) | | | | | |
* \__\_\\____|_|\__,_|___/___/_| \___/ \___/|_| |_| |_|
* 青草课堂 - index.php
* Copyright (c) 2015 - 2019.,QCTech ,All rights reserved.
* Created by: QCTech
* Created Time: 2019-01-23 - 12:13
*/
//打开缓冲区
ob_start();
header('Content-Type:text/html; charset=UTF-8');
//关掉Notice
error_reporting(E_ERROR);
// 引入配置文件
if(!file_exists("./config.php")) die("站点尚未初始化,请将config.tpl.php重命名为config.php并进行配置!");
require_once ("config.php");
//http method检查
if (!in_array($_SERVER['REQUEST_METHOD'], array('GET', 'POST'))) {
exit('Unsupported HTTP method');
}
//引入功能函数库文件
require_once ("includes/function.php");
//开启session
session_start();
// 域名检测
if($_SERVER['HTTP_HOST'] != $Config["website"]["domain"]) header("Location: "."http://".$Config["website"]["domain"]);
//数据库连接检测
$conn = new mysqli($Config["database"]["address"], $Config["database"]["username"], $Config["database"]["password"]);
if ($conn->connect_error) die("<h1>发生致命错误</h1><br />连接失败: " . $conn->connect_error);
//Router
$NotFound = true;
$HTTPParameters = array();
if (in_array($_SERVER['REQUEST_METHOD'], array('PUT', 'DELETE', 'OPTIONS'))) {
parse_str(file_get_contents('php://input'), $HTTPParameters);
}
$Routes = array(
'GET' => array(),
'POST' => array()
);
//Support HTTP Method: GET / POST
/*
* $Routes的第一维存放请求类型,第二维存放路径
* 在括号内添加正则,<>内为页面变量名称,变量值为指向目标控制器
*/
$Routes['GET']['/'] = 'home';
$Routes['GET']['/sign_up'] = 'show';
$Routes['GET']['/course(/(?<csid>[0-9]+))?'] = 'showCourse';
$Routes['GET']['/user/(?<method>.*)'] = 'user';
$Routes['POST']['/user/(?<method>.*)'] = 'user';
$Routes['GET']['/api/(?<mod>.*)'] = 'api';
$Routes['POST']['/api/(?<mod>.*)'] = 'api';
$Routes['POST']['/callback/(?<mod>.*)'] = 'callback';
$Routes['GET']['/callback/(?<mod>.*)'] = 'callback';
$Routes['GET']['/teacher/(?<mod>.*)'] = 'teacher';
$Routes['POST']['/teacher/(?<mod>.*)'] = 'teacher';
$Routes['GET']['/doc/(?<name>.*)'] = 'document';
$Routes['GET']['/note/(?<ntid>.*)'] = 'note';
//这里是Routes End
if(strpos($_SERVER['REQUEST_URI'],"?")){
$URI = substr($_SERVER['REQUEST_URI'],0, strripos($_SERVER['REQUEST_URI'], '?'));
}else{
$URI = $_SERVER['REQUEST_URI'];
}
$UrlPath = 'home';
$ParametersVariableName = '_' . $_SERVER['REQUEST_METHOD'];
foreach ($Routes[$_SERVER['REQUEST_METHOD']] as $URL => $Controller) {
if (preg_match("#^" . $URL . "$#i", $URI, $Parameters)) {
$NotFound = false;
$Parameters = array_merge($Parameters, $HTTPParameters);
foreach ($Parameters as $Key => $Value) {
if (!is_int($Key)) {
${$ParametersVariableName}[$Key] = urldecode($Value);
$_REQUEST[$Key] = urldecode($Value);
}
}
$UrlPath = $Controller;
break;
}
}
if ($NotFound === true && $_SERVER['REQUEST_METHOD']== 'GET') {
http_response_code(404);
require_once("controller/http_error.php");
die();
}elseif ($NotFound === true){
http_response_code(404);
$return = [
'status' => 'failed',
'code' => -99,
'msg' => '未知模块-'
];
die(json_encode($return));
}
if(!file_exists("controller/".$UrlPath.".php")){
require_once("controller/http_error.php");
die("路由出现问题");
}
//引入页面模板
require_once("./views/common.php");
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/qc_classrom.git
git@gitee.com:mirrors/qc_classrom.git
mirrors
qc_classrom
qc_classrom
master

搜索帮助