67 lines
1.4 KiB
PHP
67 lines
1.4 KiB
PHP
<?
|
|
/*
|
|
파일설명 : 인증용 API 페이지
|
|
생성일자 : 2021.06.22 18:00
|
|
작성자 : 박찬섭
|
|
Status Code 설명 :
|
|
200 -> 인증 통과
|
|
800 -> 인증키 없이 호출됨
|
|
801 -> 인증키 존재하지 않음
|
|
802 -> 인증기간 만료
|
|
*/
|
|
|
|
if($_GET['key'] == "" || $_GET['key'] == null) {
|
|
header("HTTP/1.1 800 Empty Key");
|
|
exit;
|
|
}
|
|
$result = GetKeyInfo($_GET['key']);
|
|
if($result == null) {
|
|
header("HTTP/1.1 801 No Key");
|
|
exit;
|
|
} else {
|
|
if(date("Y-m-d H:i:s") < date($result['expiration_at'])) {
|
|
header("HTTP/1.1 200 OK");
|
|
exit;
|
|
}
|
|
else {
|
|
header("HTTP/1.1 802 Authentication expired");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function ConnectDB() {
|
|
$user = 'dbnt0928';
|
|
$password = 'dbnt060928!';
|
|
$host = 'localhost';
|
|
$schema = 'dbnt0928';
|
|
$conn = new mysqli($host, $user, $password, $schema);
|
|
if ($conn->connect_error) {
|
|
die($conn->connect_error);
|
|
}
|
|
return $conn;
|
|
}
|
|
|
|
function DisconnsctDB($conn) {
|
|
mysqli_close($conn);
|
|
}
|
|
|
|
function GetKeyInfo($key) {
|
|
$conn = ConnectDB();
|
|
$query = "select * from authkey where name='$key'";
|
|
$result = mysqli_query($conn, $query);
|
|
if (mysqli_num_rows($result) > 0) {
|
|
while($row = mysqli_fetch_assoc($result)) {
|
|
return array(
|
|
"name" => $row["name"],
|
|
"company" => $row["company"],
|
|
"descripyion" => $row["descripyion"],
|
|
"created_at" => $row["created_at"],
|
|
"expiration_at" => $row["expiration_at"]);
|
|
}
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
?>
|