250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 동적sql
- 일대다
- FetchType
- 스토어드 프로시저
- dfs
- exclusive lock
- 낙관적락
- eager
- 다대일
- fetch
- CHECK OPTION
- JPQL
- 백트래킹
- 연관관계
- SQL프로그래밍
- 데코레이터
- 즉시로딩
- 유니크제약조건
- 이진탐색
- PS
- 스프링 폼
- execute
- shared lock
- 다대다
- 비관적락
- BOJ
- 지연로딩
- 연결리스트
- 힙
- querydsl
Archives
- Today
- Total
흰 스타렉스에서 내가 내리지
[php] 간단한 로그인 구현 본문
728x90
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script>
$(function(){
var $frm = $(".login_f");
$frm.on("submit", function(e){
e.preventDefault(); // [submit] 버튼을 눌러도 action 페이지로 이동하지 않습니다.
var myData = $frm.serialize(); //사용자가 폼 입력 요소에 작성한 값을 쿼리 스트링 형식의 데이터로 변환하여 myData에 대입한다.
$.ajax({
type:"POST",
url:$frm.attr("action"),
data:myData,
success:function(res){
if(res){
//res에 요청한 데이터를 받아온다. 그런 다음 res를 json 형식으로 변형하여 jsonData에 대입
var jsonData = JSON.parse(res);
var message = jsonData.user_name + "(" + jsonData.user_id + ")" + "님 반갑습니다.";
$(".login_wrap").html(message);
}
}
});
});
});
</script>
</head>
<body>
<div class="login_wrap">
<h1>로그인</h1>
<form class="login_f" method="post" action="login_ok.php">
<p>
<label for="user_id">아이디</label>
<input type="text" name="user_id" id="user_id" value="1avn">
</p>
<p>
<label for="user_pw">비밀번호</label>
<input type="password" name="user_pw" id="user_pw" value="12345">
</p>
<p><input type="submit" value="로그인" class="login_btn" /></p>
</form>
</div>
</body>
</html>
<?php
if(!isset($_POST['user_id']) || !isset($_POST['user_pw']))
exit;
$user_id = $_POST['user_id'];
$user_pw = $_POST['user_pw'];
$members = array(
'1avn'=>array('pw'=>'12345', 'name'=>'1여단'),
'2avn'=>array('pw'=>'12345', 'name'=>'2여단')
);
if(isset($members[$user_id]) && $members[$user_id]['pw']==$user_pw){
echo '{"user_id" : "'.$user_id.'", "user_name" : "'.$members[$user_id]['name'].'"}';
}
?>