티스토리 뷰

로그인 폼과 로그인시 ID,PW 확인하는 코드입니다. 

CSS는 취향에 맞춰 만들어주세요.

직접 만든 코드라 서툴러도 이해해주세요 ㅎㅎ

 

 

<logIn.php>

<!DOCTYPE html>
    <?php 
    include "session.php";
     ?>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="main.css">
        <title></title>
    </head>
    <center>
    <body>
        <br><br><br><br><h1>LOGIN</h1><br><br>
        <form method="post" action="signIn.php">
            <input type="text" name="userId"><br><br>
            <input type="password" name="userPw"><br><br><br><br>
            <button type="submit">LOGIN</button>
            <button type="button"><a href="register.html">REGISTER</a></button>
        </form>
    </body>
    </center>
</html>

 

<signIn.php>

 <?php 
  include "session.php";
  include "./dbConnect.php";

  $connect = new mysqli($host, $user, $pw, $dbName);

  $query = "select userId,userPw from member";
  $result = mysqli_query($mysqli,$query);
  $userId = $_POST['userId'];
  $userPw = $_POST['userPw'];
  $check="select * from member where userId='$userId'"; 
  $result=$mysqli->query($check);
    $row=$result->fetch_array(MYSQLI_ASSOC);
  
    if($row['userPw']==$userPw){

      setcookie('session_Id', $userId, time()+86300, '/');
      setcookie('logIn_time', time(), time()+86300, '/');
      setcookie('session_Pw', $userPw, time()+3600, '/');

      echo "<script>alert('$userId 님, 반갑습니다'); location.href='main.php';</script>";

    }
    else {
        echo "<script>alert('ID와 PW를 확인해주세요'); location.href='./logIn.php';</script>";
    }


 ?>

 

<session.php>

<?php
	session_start();
?>

 

 

<결과물>

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday