main.php
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>main</title>
</head>
<body>
<?php
session_start();
if(!isset($_SESSION['user_id']))
{
header('Location: login.html');
}
echo "홈(로그인 성공)";
echo "<a href=logout.php>로그아웃</a>";
?>
</body>
</html>
login_check.php
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>login_check</title>
</head>
<body>
<?php
session_start();
$id = $_POST['id'];
$pw = $_POST['pw'];
$mysqli = mysqli_connect("localhost", "root", "pass", "test");
$check = "SELECT * FROM user WHERE user_id = '$id'";
$result = $mysqli -> query($check);
if($result -> num_rows == 1)
{
$row = $result -> fetch_array(MYSQLI_ASSOC);
if($row['user_password'] == $pw)
{
$_SESSION['user_id'] = $id;
if(isset($_SESSION['user_id']))
{
echo "성공";
sleep(3);
header('Location: main.php');
}
else
{
echo "세션 저장 실패";
}
}
else
{
echo "아이디 또는 비밀번호가 틀립니다";
}
}
else
{
echo "아이디 또는 비밀번호가 틀립니다";
}
?>
</body>
</html>
logout.php
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>logout</title>
</head>
<body>
<?php
session_start();
$res = session_destroy();
if($res)
{
header('Location: ./main.php');
}
?>
</body>
</html>
signup.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sign Up</title>
</head>
<body>
<form action="./signup.php" method="post">
<div>
<label for="id"> ID </label>
<input type="text" name="id" />
</div>
<div>
<label for="pw"> PW </label>
<input type="password" name="pw" />
</div>
<div>
<label for="pwc"> PWC </label>
<input type="password" name="pwc" />
</div>
<div>
<label for="name"> Name </label>
<input type="text" name="name" />
</div>
<div>
<label for="email"> E-mail </label>
<input type="email" name="email" />
</div>
<div class="button">
<input type="submit" value="submit">
</div>
</form>
</body>
</html>
signup.php
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>signUp</title>
</head>
<body>
<?php
$id = $_POST['id'];
$pw = $_POST['pw'];
$pwc = $_POST['pwc'];
$name = $_POST['name'];
$email = $_POST['email'];
if($pw != $pwc)
{
echo "비밀번호와 비밀번호 확인이 서로 다릅니다.";
echo "<a href=signup.html>bank page</a>";
exit();
}
if($id == NULL || $pw == NULL || $name == NULL || $email == NULL)
{
echo "빈 칸을 모두 채워주세요";
echo "<a href=signup.html>back page</a>";
exit();
}
$mysqli = mysqli_connect("localhost", "root", "pass", "test");
$check = "SELECT * FROM user WHERE user_id='$id'";
$result = $mysqli -> query($check);
if($result -> num_rows == 1)
{
echo "중복된 id입니다.";
echo "<a href=signup.html>back page</a>";
exit();
}
$signup = mysqli_query($mysqli, "INSERT INTO user (user_id, user_pw, name, email) VALUES('$id', '$pw', '$name', '$email')");
if($signup)
{
echo "sign up success";
}
?>
</body>
</html>
login.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>login page</title>
</head>
<body>
<form action="login_check.php" method="post">
<div>
<label for="id">ID </label>
<input type="text" name="id" />
</div>
<div>
<label for="pw">PW </label>
<input type="password" name="pw" />
</div>
<div claass="button">
<button type="submit"> login </button>
</div>
</form>
<button onClick="location.href='signUp.html'"> sign up </button>
</body>
</html>
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 71 | 포트 상태 확인 및 포트 열기 | proin | 2018.06.05 | 0 |
| 70 | [WEB] 회원가입 부분 기본 틀 | proin | 2018.06.04 | 1 |
| 69 | MySQL 패스워드 변경 | proin | 2018.06.01 | 0 |
| 68 | DB계정 관련 | proin | 2018.06.01 | 2 |
| 67 | html 문서에서 php 코드가 실행이 안될 때 | proin | 2018.05.29 | 3 |
| 66 | onclick 링크 (새창/팝업/현재창/프레임) | proin | 2018.05.29 | 0 |
| 65 | [WEB] DIV 태그를 이용하여 레이아웃 만들기 | proin | 2018.05.28 | 0 |
| 64 | MySQL 숫자 | proin | 2018.05.28 | 0 |
| 63 | crontab 명령어 | proin | 2018.05.27 | 1 |
| 62 | MySQL Database Dump 명령 | proin | 2018.05.27 | 0 |
| 61 | [WEB] css 버튼 디자인 모음 | proin | 2018.05.23 | 0 |
| 60 | [WEB] 제타위키 세션 PHP 로그인 | proin | 2018.05.23 | 0 |
| » | [WEB] 세션 PHP 로그인 | proin | 2018.05.23 | 2 |
| 58 | PHP를 이용한 Header 페이지 이동(리다이렉트Redirect) | proin | 2018.05.21 | 0 |
| 57 | [아두이노] 블루투스로 컨트롤하는 무선조종 자동차 | proin | 2018.05.21 | 1 |
| 56 | [아두이노] Arduino MEGA 핀배열 | proin | 2018.05.21 | 3 |
| 55 | [아두이노] DC 모터 조이스틱 속도 제어 | proin | 2018.05.16 | 1 |
| 54 | [아두이노] DC 모터의 속도제어(모터드라이버 L298N) 2편 | proin | 2018.05.14 | 4 |
| 53 | How to Use the Arduino Joystick Shield v2.4 | proin | 2018.05.14 | 0 |
| 52 | Joystick Shield Module V1.A | proin | 2018.05.14 | 0 |