반응형

[Project1]로그인 구현하기 

완성한것 첨부파일 하였습니다. ^^

로그인실패시 창에 나오게 되는 starterror.php 또한 함께 첨부되었습니다.



htdocs.zip





htdocs.zip
0.0MB
반응형
반응형


[Project1]로그인 구현하기  (php, mysql, html)_ 로그인(login.php)


설명은 주석으로 잘설명해 두었습니다.

그런데 앞부분에

session.php 는 무엇일까요

session.php에서는 session이 끝나기전까지 유지시켜줍니다.

session.php

1
2
3
4
<?php
    session_cache_limiter("private_no_expire");
    session_start();        //세션시작에 실패하면 false 반환   에러시 무시: @sesison_start(); 또는 output_buffering=on인지 확인
?>
cs



login.php

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

    <?
    include"session.php";   //session.php파일을 포함

    ?>
 
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>DB</title>
    <style>
     a:link {
     color: black;
     background-color: transparent;
     text-decoration: none;
     }
     a:visited {
     color: gray;
     background-color: transparent;
     text-decoration: none;
     }
     a:hover {
     color: gray;
     background-color: transparent;
     text-decoration: underline;
     }
     a:active {
     color: black;
     background-color: transparent;
     text-decoration: underline;
     }
      #jb-container {
        width: 940px;
        height: 450px;
        margin: 0px ;
        padding: 20px;
        border: 1px solid #bcbcbc;
      }
      #jb-header {
        padding: 20px;
        margin-bottom: 20px;
        border: 1px solid #bcbcbc;
      }
      #jb-sidebar-left {
        width: 650px;
        height: 170px;
        padding: 20px;
        margin-right: 20px;
        margin-bottom: 20px;
        float: left;
        border: 1px solid #bcbcbc;
      }
      #jb-content {
        width: 450px;
        padding: 20px;
        margin-bottom: 20px;
        float: left;
        border: 1px solid #bcbcbc;
      }
      #jb-sidebar-right {
        width: 160px;
        padding: 20px;
        margin-bottom: 20px;
        float: right;
        border: 1px solid #bcbcbc;
      }
      #jb-footer {
        clear: both;
        padding: 20px;
        border: 1px solid #bcbcbc;
      }
    </style>
  </head>
 
 
<body>
    <div id="jb-container">
      <div id="jb-header">
        <h1>WELCOME</h1>
      </div>
      <div id="jb-sidebar-left">
        <h2>Menu</h2>
        <ul>
 
          <li><a href="10.html " >관리</a></li><br>
          <li><a href="20.html " >게시판</a></li><br>
          <li><a href="30.html " >검증</a></li><br>
 
        </ul>
      </div>
 
      <div id="jb-sidebar-right">

        <?php 

    
    $host = 'localhost'; 
    $user = 'root';
    $pw = '111111';
    $dbName = 'opentutorials';
    $mysqli = new mysqli($host, $user, $pw, $dbName); //mysql로 접근 하도록 설정
    $memberId = $_POST['id'];
    $memberPw = $_POST['password'];
    $sql = "SELECT * FROM member WHERE id = '$memberId' AND pwd = '$memberPw'"; //my sqli 연결의 끈을 생성시키고, 쿼리를 실행
      //고른다 모든것 member테이블로부터 id와 pwd가 일치하는 것을
    $res = $mysqli->query($sql); //실행결과는 $res에 저장
 
 
        $row = $res->fetch_array(MYSQLI_ASSOC); // 넘어온 결과를 한 행씩 패치해서 $row라는 배열에 담는다.
 
        if ($row != null) {                                                 //만약 배열에 존재한다면
            $_SESSION['ses_username'] = $row['name'];                           // 세션을 만들어준다. 
            echo $_SESSION['ses_username'].'님 안녕하세요<p/>';                   // name님 안녕하세요.
            echo '<a href="./index.php">로그아웃 하기</a>';           //로그아웃 페이지 링크.
        }
 
        if($row == null){                                                    //만약 배열에 아무것도 없다면
            
         echo("<script>location.href='RSDB_starterror.php';</script>");          //애러 화면으로 넘김
 
 
            
        }
 
 
?>


 
      </div>
 
    </div>
  </body>
</html>

cs


반응형
반응형

회원가입을 했는데,  submit 해서 전송 시켰지만, 회원정보를 저장해야겠죠.

저장되는 곳이 sql 이고!

저장되도록 처리해주는 부분이 membersave.php부분입니다.

저번에 올렸던것을 다시 보시면,

form으로 membersave.php로 전달했습니다. 

사용자가 입력한 id, password, name, position 등을 membersave.php로 전달 받은 것입니다.

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
32
33
<doctype html>
<html>
<head>
<meta charset="utf-8">
<title>sign up page</title>
</head>
<body>

<form name="join" method="post" action="memberSave.php"> <!--membersave.php 파일로 회원정보저장-->


 <h1>input your information</h1>
 <table border="1">
  <tr>
   <td>ID</td>
   <td><input type="text" size="30" name="id"></td>
  </tr>
  <tr>
   <td>Password</td>
   <td><input type="password" size="30" name="pwd"></td>
  </tr>
  <tr>
   <td>name</td>
   <td><input type="text" size="12" maxlength="10" name="name"></td>
  </tr>
  <tr>
   <td>Position</td>
   <td><input type="text" size="30" name="position"></td>
  </tr>
 </table>

 <input type=submit value="submit"><input type=reset value="rewrite">


 
   <input type="button" value="뒤로가기"onclick="javascript:history.go(-1)">
</form>
</body>
</html>
cs




저장되는 처리를 해주기전에

실제로 데이터가 저장되는! 저장받을 공간(sql)을 만들어줘야겠죠!


CREATE TABLE `member` (

  `id` varchar(30) NOT NULL COMMENT '회원 아이디',

  `pwd` varchar(20) NOT NULL COMMENT '회원 비밀번호',

  `name` varchar(10) NOT NULL COMMENT '회원 이름',

  `position` varchar(20) DEFAULT NULL COMMENT '회원 직급',

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8



not null 의 의미는 비어서는 안된다는 것입니다. null = 아무것도 없다 

varchar은 가변길이 데이터 <-> 고정길이데이터 char

varchar(30) 30은 30개 문자 저장 가능을 의미합니다.

comment는 주석입니다~

default null 은 기본값으로 아무것도 주지 않겠다는 의미입니다.


innodb ( MYISAM보다 많은 기능을 제공 : COMMIT, ROLBACK등등) 형식으로 table이 생성되었고, table에 저장되어있는 데이터는 utf-8 형식 사용합니다.






시작-> 실행 들어간뒤

cmd 라고 입력한후 명령 프롬프트에 들어갑니다.


그후 , mysql.exe파일 경로를 복사하여

cd mysql.exe파일 경로 이렇게 입력합니다.

그후 

mysql -uroot -p비밀번호 -hlocalhost 라고 입력합니다.

비밀번호는,, 서버를 깔며 입력했을것입니다.

(sq설정에 대한부분은 따로 게시하겠습니다.)


그후 create database opuntutorials character set utf 8 collate utf8_general_ci; 로 입력해 데이터베이스(opentutorials)를 생성해줍니다.

use opentutorials;를 입력해 db로 들어간뒤


위의 create table 'member'부분을 입력해서 table을 만들어줍니다.



이렇게 해서 저장받을 공간은 만들어졌습니다.

그뒤, join.php -> opentutorials(mysql)로 가기 위해선

membersave.php 를 통해 처리시켜 주어야 합니다.



membersave.php

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
<html>
   <meta charset="utf-8">
<?php
 
$host = 'localhost';
$user = 'root';
$pw = '111111';
$dbName = 'opentutorials';
$mysqli = new mysqli($host$user$pw$dbName);
 
 $id=$_POST['id'];
 $password=($_POST['pwd']);
 $name=$_POST['name'];
 $position=$_POST['position'];
 
 
 $sql = "insert into member (id, pwd, name, position)";             // (입력받음)insert into 테이블명 (column-list)
 $sql = $sql"values('$id','$password','$name','$position')";         // calues(column-list에 넣을 value-list)
 if($mysqli->query($sql)){                                                              //만약 sql로 잘 들어갔으면
  echo 'success inserting <p/>';                                                            //success inserting 으로 표시
  echo $name.'님 가입 되셨습니다.<p/>';                                   // id님 안녕하세요.
 }else{                                                                                //아니면
  echo 'fail to insert sql';                                                            //fail to insert sql로 표시
 }
mysqli_close($mysqli);
 
 
?>
<input type="button" value="로그인하러가기" onclick="location='index.php'">
</html>
cs


<?php
 
$host = 'localhost';
$user = 'root';
$pw = '111111';
$dbName = 'opentutorials';
$mysqli = new mysqli($host$user$pw$dbName);


이부분은, mysql과 php를 연동시켜주는 부분입니다.



 $id=$_POST['id'];
 $password=($_POST['pwd']);
 $name=$_POST['name'];
 $position=$_POST['position'];


join.php에서 post로 전달받은 id, pwd, name, position (name=이곳에써있었던 변수명) 을 post로 전달받아 다시 id, password, name, position이라고 변수로 저장시켜줍니다.


$sql = "insert into member (id, pwd, name, position)";             // (입력받음)insert into 테이블명 (column-list)
 $sql = $sql"values('$id','$password','$name','$position')"


쿼리문이죠!

insert into member (id, pwd, name, position) mysql의 테이블 명

"values('$id','$password','$name','$position')" 이부분은 아까 join.php에서 post방식으로 받아와 다시 변수로 받았던 것입니다.

$sql = $sql점의 의미는 기존변수의 문자열에 다른 문자를 추가시키는 의미입니다.



if($mysqli->query($sql)){                                                              //만약 sql로 잘 들어갔으면
  echo 'success inserting <p/>';                                                            //success inserting 으로 표시
  echo $name.'님 가입 되셨습니다.<p/>';                                   // id님 안녕하세요.
 }else{                                                                                //아니면
  echo 'fail to insert sql';                                                            //fail to insert sql로 표시
 }
mysqli_close($mysqli);
?>


if문이죠

$mysqli->query($sql) 쿼리문이 잘 들어갔다면,의미

mysqli_close($mysqli); mysqli 종료 의미


<input type="button" value="로그인하러가기" onclick="location='index.php'">
</html>


결과입니다.





반응형
반응형

[Project1]로그인 구현하기  (php, mysql, html)


이제 로그인 할 화면을 만들었으니, 회원가입할 화면을 만들어야겠죠.

아래와 같습니다. 

그런데 왜 ! join.php 라고 이름을 지었을까요? 


왜냐하면, 

index.php 첫화면 에서 회원가입 버튼부분에

<input type="button" name ="버튼" value="회원가입" onclick="location.href='http://localhost/join.php'";>

이렇게, join.php로 가도록 만들어주었기 때문이죠~



join.php


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
32
33
<doctype html>
<html>
<head>
<meta charset="utf-8">
<title>sign up page</title>
</head>
<body>
<form name="join" method="post" action="memberSave.php"<!--membersave.php 파일로 회원정보저장-->
 <h1>input your information</h1>
 <table border="1">
  <tr>
   <td>ID</td>
   <td><input type="text" size="30" name="id"></td>
  </tr>
  <tr>
   <td>Password</td>
   <td><input type="password" size="30" name="pwd"></td>
  </tr>
  <tr>
   <td>name</td>
   <td><input type="text" size="12" maxlength="10" name="name"></td>
  </tr>
  <tr>
   <td>Position</td>
   <td><input type="text" size="30" name="position"></td>
  </tr>
 </table>
 <input type=submit value="submit"><input type=reset value="rewrite">
 
   <input type="button" value="뒤로가기"onclick="javascript:history.go(-1)">
</form>
</body>
</html>
cs

조금씩 나누어 설명드리겠습니다. ^^

<doctype html>
<html>
<head>
<meta charset="utf-8">
<title>sign up page</title>
</head>


<doctype html>

html 버전별로 지원하는 태그가 다릅니다. 따라서 웹브라우저에게 html버전을 미리 선언해 주어, 내용을 올바르게 표시 할 수 있도록 합니다.

<meta charset="utf-8">

전세계 모든 문자를 한꺼번에 인코딩(컴퓨터에서 문자 정보를 처리하는 일련의 과정)해줍니다.

<title>sign up page</title>

tool bar에 표시되는 부분입니다.



<body>
<form name="join" method="post" action="memberSave.php"<!--membersave.php 파일로 회원정보저장-->
 <h1>input your information</h1>


<form name="join" method="post" action="memberSave.php"

form으로 post라는 변수 전달 방식을 통해 membersave.php페이지로 변수를 전달받죠 ^^

<h1>input your information</h1>

강조해서 글씨를 써줍니다. input your information이라는 글씨를 강조~!


<table border="1">
  <tr>
   <td>ID</td>
   <td><input type="text" size="30" name="id"></td>
  </tr>
  <tr>
   <td>Password</td>
   <td><input type="password" size="30" name="pwd"></td>
  </tr>
  <tr>
   <td>name</td>
   <td><input type="text" size="12" maxlength="10" name="name"></td>
  </tr>
  <tr>
   <td>Position</td>
   <td><input type="text" size="30" name="position"></td>
  </tr>
 </table>


<table border="1">

table (표)의 굵기가 1이라는 의미죠 ~



<tr>
   <td>ID</td>
   <td><input type="text" size="30" name="id"></td>
  </tr>
  <tr>
   <td>Password</td>
   <td><input type="password" size="30" name="pwd"></td>
  </tr>


<tr> </tr> 행

<td> </td> 열 

한마디로 이러한 형태죠 


id

input type="text"

password

input type="password"


input type 부분은 어떤형식으로 입력을 받을지에 대한 부분 입니다.

password의 경우 , *******이런식으로 입력받죠.~



<input type=submit value="submit"><input type=reset value="rewrite">
 
   <input type="button" value="뒤로가기"onclick="javascript:history.go(-1)">
</form>
</body>
</html>

<input type=submit value="submit"> 변수전달

<input type=reset value="rewrite"> reset : 입력한 모든것을 지워줍니다.

<input type="button" value="뒤로가기"onclick="javascript:history.go(-1)"> 뒤로가기 기능



결과입니다 ~






반응형

+ Recent posts