로그인 후 쿠키값이 생성되었을 때 사이트에 접속하면 로그인이 되어있다고 뜨게 만드는 코드입니다.
<index.php>
<?php
session_start();
include "dbConnect.php";
?>
<html lang="en">
<center>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="./main.css">
<body>
<h1>Account Login</h1>
<?php
if(!isset($_COOKIE['session_Id']) && !isset($_COOKIE['logIn_time']) && !isset($_COOKIE['session_Pw'])) {
echo "<script>alert('로그인해주세요'); location.href='logIn.php';</script>";
} else {
echo "<script>alert('이미 로그인 되어있습니다.');</script>";
echo "<a href=main.php>Home</a>";
}
?>
</body>
</center>
</html>
<결과물>
'웹 공부 > 웹 개발 (APM)' 카테고리의 다른 글
ubuntu) html 코드 안의 PHP 코드가 실행되지 않을 때 (주석처리 될 때) (2) | 2020.01.15 |
---|---|
웹 개발 #파일 다운로드 코드 (0) | 2019.07.24 |
웹 개발 #로그아웃, 쿠키 삭제 코드 (0) | 2019.06.24 |
웹 개발 #메인페이지 코드 (0) | 2019.06.24 |
웹 개발 #CSS 코드 (0) | 2019.06.24 |