代码拉取完成,页面将自动刷新
<?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");
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。