티스토리 뷰

SWDesk/Web

Cookie Test

bizmaker 2020. 6. 13. 23:44

쿠키 테스트 소스 모음

CookieTest.zip
0.00MB

<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
링크
«   2025/03   »
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
글 보관함