인트로 페이지에 인증코드를 넣고 맞으면 넘어 가고 아니면 인증페이지 그대로 이도록 하고 있습니다.
아래처럼 처리 했는데 계속 auth.php로 넘어오는데 무엇이 문제 일까요?
Copy
먼저 index.php
<?php
define('_INDEX_', true);
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
session_start(); // 세션을 시작합니다.
if (!isset($_SESSION['authenticated'])) { // 인증되지 않은 경우, auth.php로 이동합니다.
header('Location: auth.php');
exit;
}
이하 생략
.
.
이렇게 넣고
auth.php에는
<?php
$auth_codes = array('code1', 'code2', 'code3'); // 여러 개의 인증 코드 중에서 사용할 코드를 이 배열에 추가하세요.
if (isset($_POST['auth_code'])) {
$input_code = $_POST['auth_code'];
if (in_array($input_code, $auth_codes)) {
session_start();
$_SESSION['authenticated'] = true;
header('Location: index.php'); // 인증에 성공하면 다시 index.php로 돌아갑니다.
exit;
} else {
echo '인증 코드가 잘못되었습니다.';
}
}
?>
<form method="post">
<label for="auth_code">인증 코드 입력:</label>
<input type="text" name="auth_code">
<input type="submit" value="확인">
</form>
|
답변 3개 / 댓글 1개
채택된 답변
+20 포인트
답변을 작성하려면 로그인이 필요합니다.