15-9. 로그인 기능 만들기
https://www.opentutorials.org/course/1688/9372
1) 자바스크립트로 로그인 기능 구현하기
prompt 명령어
- 텍스트를 입력 받는 형태의 대화상자를 띄운다.
7.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> </head> <body> <script charset="utf-8"> password = prompt("비밀번호"); if(password == 1111) { // 로그인 성공 document.write("안녕하세요. 주인님"); } else { // 로그인 실패 document.write("뉘신지?"); } </script> </body> </html> | cs |
2) PHP로 로그인 기능 구현하기
- 사용자가 submit 버튼을 누르면, form 태그 안에 있는 input 태그에 입력된 정보들을 form 태그의 action 속성이 가리키는 페이지를 웹브라우저가 열면서 그 뒤에다가 ?(물음표)를 단 후에 정보들의 값을 위치시킨다.
ex) ..../8-2.php?password=1111
$_GET 변수
- HTTP GET 방식으로 전송된 정보들의 name과 값 배열
8-1.php
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> </head> <body> <form action="8-2.php"> <p>비밀번호를 입력해주세요.</p> <input type="text" name="password"> <input type="submit"> </form> </body> </html> | cs |
8-2.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> </head> <body> <?php $password = $_GET["password"]; if($password == "1111"){ // 로그인 성공 echo "주인님 환영합니다"; } else{ // 로그인 실패 echo "뉘신지?"; } ?> </body> </html> | cs |
'컴퓨터 > 웹 개발' 카테고리의 다른 글
[코딩야학] ~ 프로그래밍 접근방법 - 10일차 (0) | 2017.08.01 |
---|---|
[코딩야학] ~ 배열 - 9일차 (0) | 2017.07.31 |
[코딩야학] ~ 조건문 - 7일차 (0) | 2017.07.31 |
[코딩야학] ~ 웹페이지에 코드삽입 - 6일차 (0) | 2017.07.31 |
[코딩야학] ~ CSS실습 - 5일차 (0) | 2017.07.31 |