티스토리 뷰
쿠키 테스트 소스 모음
<CookieTest1_Main.php>
<source lang='php'>
<!DOCTYPE html>
<meta charset="utf-8" />
<?php
if(!isset($_COOKIE['user_id']) || !isset($_COOKIE['user_name'])) {
echo "<meta http-equiv='refresh' content='0;url=CookieTest1_Login.php'>";
exit;
}
$user_id = $_COOKIE['user_id'];
$user_name = $_COOKIE['user_name'];
echo "<p>안녕하세요. $user_name($user_id)님</p>";
echo "<p><a href='CookieTest1_Logout.php'>로그아웃</a></p>";
?>
</source>
<CookieTest1_Login.php>
<source lang='html5'>
<!DOCTYPE html>
<meta charset="utf-8" />
<form method='post' action='CookieTest1_LoginOK.php'>
<table>
<tr>
<td>아이디</td>
<td><input type='text' name='user_id' tabindex='1' /></td>
<td rowspan='2'><input type='submit' tabindex='3' value='로그인' style='height:50px' /></td>
</tr>
<tr>
<td>비밀번호</td>
<td><input type='password' name='user_pw' tabindex='2' /></td>
</tr>
</table>
</form>
</source>
<CookieTest1_LoginOK.php>
<source lang='php'>
<meta charset="utf-8" />
<?php
if(!isset($_POST['user_id']) || !isset($_POST['user_pw'])) exit;
$user_id = $_POST['user_id'];
$user_pw = $_POST['user_pw'];
$members = [
'user#1'=>['pw'=>'password#1', 'name'=>'네임#일'],
'user#2'=>['pw'=>'password#2', 'name'=>'네임#이'],
'user#3'=>['pw'=>'password#3', 'name'=>'네임#삼'],
];
if(!isset($members[$user_id])) {
echo "<script>alert('아이디 또는 패스워드가 잘못되었습니다.');history.back();</script>";
exit;
}
if($members[$user_id]['pw'] != $user_pw) {
echo "<script>alert('아이디 또는 패스워드가 잘못되었습니다.');history.back();</script>";
exit;
}
setcookie('user_id',$user_id,time()+(86400*30),'/');
setcookie('user_name',$members[$user_id]['name'],time()+(86400*30),'/');
?>
<meta http-equiv='refresh' content='0;url=main.php'>
</source>
<CookieTest1_Logout.php>
<source lang='php'>
<meta charset="utf-8" />
<?php
setcookie('user_id', '', time()-3600, '/');
setcookie('user_name', '', time()-3600, '/');
?>
<meta http-equiv='refresh' content='0;url=main.php'>
</source>
반응형
'SWDesk > Web' 카테고리의 다른 글
PHP + Python Test (0) | 2020.06.23 |
---|---|
[BPM] Updating Sources for Manager (0) | 2020.06.15 |
Identifying IFTTT Key (1) | 2020.05.11 |
DB 내 데이터를 백업하기 위한 예제 소스 코드 (0) | 2020.05.03 |
[PHP] Date, Timestamp (0) | 2020.04.19 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 절연형
- Video
- 오블완
- Innovations
- 심심풀이
- 치매
- 빌리언트
- BSC
- 아두이노
- 둎
- 배프
- Innovations&Hurdles
- 전압
- image
- Decorator
- 혁신과허들
- arduino
- ServantClock
- Hurdles
- badp
- 전류
- 치매방지
- DYOV
- bilient
- Innovation&Hurdles
- 혁신
- 전압전류모니터링
- 티스토리챌린지
- 심심풀이치매방지기
- 허들
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함