旧版服务端
This commit is contained in:
1 parent
3429c8b402
commit
25bbb5f9c8
971 files changed
+87141
-40
No files matched your search
Executable
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// 前端传入的课程口令码
|
||||
$courseCode = $_GET['CourseCode']; // 使用GET方法传入口令码
|
||||
|
||||
// 声明输出为JSON
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// 引用配置,建立数据库连接
|
||||
require_once 'ApiConfig.php';
|
||||
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
|
||||
|
||||
// 检查连接是否成功
|
||||
if ($conn->connect_error) {
|
||||
die("连接失败: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// 查询课程口令码表中符合条件的数据
|
||||
$sql = "SELECT * FROM 课程口令码 WHERE 口令码 = '$courseCode'";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
// 检查是否有符合条件的数据
|
||||
if ($result->num_rows > 0) {
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
// 获取口令起始日期和口令结束日期
|
||||
$startDate = strtotime($row['口令起始日期']);
|
||||
$endDate = strtotime($row['口令结束日期']);
|
||||
$now_time = date('Y-m-d H:i:s');
|
||||
$current_time = strtotime($now_time);
|
||||
// 比较口令日期
|
||||
if ($startDate <= $current_time && $current_time <= $endDate) {
|
||||
// 口令有效,输出课程id和课程字段
|
||||
$output = array(
|
||||
'课程id' => $row['课程id'],
|
||||
'课程' => $row['课程']
|
||||
);
|
||||
echo json_encode($output);
|
||||
} else {
|
||||
// 口令失效
|
||||
|
||||
echo json_encode("口令失效");
|
||||
}
|
||||
} else {
|
||||
// 没有找到符合条件的数据
|
||||
echo json_encode("口令码不存在");
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in new issue
Block a user