PHP 프로그래밍

본문 바로가기
사이트 내 전체검색


Web Programming >> PHP Programming
[목차]
제24장 쇼핑몰 만들기 2

    3. 고객용 회원가입 및 로그인 프로그램

필요한 프로그램들 다음과 같다.

/ --  shop/ -- admin/ --- member/ --(회원관리 추가)

             |         |            |

             |         |            +-- list.html

             |         |            +-- viewbody.html

             |         |            +-- modifyform.html

             |         |            +-- modify.html

             |         |            +-- deleteform.html

             |         |            +-- delete.html

             |         +- menu.html (관리자 메뉴 수정)

             +-- menu.html (쇼핑몰 메뉴 수정)

             |

             +-- registerform.html (회원가입 폼)

             +-- register.html (회원가입 처리)

             +-- check_id.html (ID 중복확인 프로그램)

             +-- login.html (로그인 폼)

             +-- login_process.html (로그인 처리)

             +-- logout.html (접속 종료)

1. 회원가입하기

파일명 : registerform.hrml

<HTML>

<HEAD>

<TITLE>LeeLAB - 회원 가입</TITLE>

<SCRIPT LANGUAGE='JavaScript'>

function form_submit()

{

        if(!document.registerform.name.value)

        {

                alert('이름을 입력하여 주세요.');

                document.registerform.name.focus();

        }

        else if(!document.registerform.id.value)

        {

                alert('아이디를 입력하여 주세요.');

                document.registerform.id.focus();

        }

        else if(!document.registerform.passwd.value)

        {

                alert('비밀번호를 입력하여 주세요.');

                document.registerform.passwd.focus();

        }

        else if(!document.registerform.passwd1.value)

        {

                alert('비밀번호를 확인하여 주세요.');

                document.registerform.passwd1.focus();

        }

        else if(document.registerform.passwd1.value != document.registerform.passwd.value)

        {

                alert('비밀번호 확인에 실패하였습니다. 다시 입력하여 주세요.');

                document.registerform.passwd.value = '';

                document.registerform.passwd1.value = '';

                document.registerform.passwd.focus();

        }

                else {

                        document.registerform.submit();

        }

}

 

 

function idchk()

{

        if(!document.registerform.id.value)

        {

                alert('아이디를 입력하여 주세요.');

                document.registerform.id.focus();

        }

        else

        {

                tmp = 'check_id.html?id='+document.registerform.id.value;

                window.open(tmp,'IDCHK','width=300,height=150,scrollbars=no');

        }

}

 

</SCRIPT>

</HEAD>

<BODY>

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 회원 가입 ]</FONT><BR>

 

<FORM METHOD=POST ACTION=register.html NAME=registerform>

<TABLE border cellpadding=3 cellspacing=0 bordercolor=#545F81 width=400>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER WIDTH=100 bgcolor=#B3BBCD><FONT SIZE=2>이 름</FONT></TD>

        <TD WIDTH=300><FONT SIZE=2><INPUT TYPE=TEXT NAME=name SIZE=15 MAXLENGTH=8></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>아이디</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=TEXT NAME=id SIZE=15 MAXLENGTH=8>&nbsp;&nbsp;&nbsp;&nbsp;

                <INPUT TYPE=BUTTON VALUE='아이디 중복 확인' onclick='idchk();'></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>비밀번호</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=PASSWORD NAME=passwd SIZE=15 MAXLENGTH=8></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>비밀번호확인</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=PASSWORD NAME=passwd1 SIZE=15 MAXLENGTH=8></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>E-Mail</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=TEXT NAME=email SIZE=40 MAXLENGTH=50></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>주소</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=TEXT NAME=address SIZE=40 MAXLENGTH=100></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>전화번호</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=TEXT NAME=tel SIZE=15 MAXLENGTH=15></TD>

</TR>

 

</TABLE><br>

<TABLE WIDTH=400>

<TR>

        <TD ALIGN=CENTER><INPUT TYPE=BUTTON VALUE='가입신청' onclick='form_submit();'>&nbsp;&nbsp;<input type=button

value='뒤로가기' onclick='history.back()'></TD>

</TR>

</TABLE>

</FORM>

 

 

 

 

파일명 : register.html

<?

include "../user_function.html";

include "../dbconn.html";

 

if($id && $name)

{

        $query = "SELECT * FROM member WHERE id='$id'";

        $result = mysql_query($query);

        if($row = mysql_fetch_row($result))

        {

                echo "<SCRIPT>alert('이미 사용중인 아이디 입니다.');history.go(-1);</SCRIPT>";

                exit;

        }

 

        $query = "INSERT INTO member (name,id,passwd,email,address,tel) VALUES ('$name','$id','$passwd','$email','$address','$tel')";

        mysql_query($query);

        echo "

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 회원 가입 확인]</FONT><BR>

 

<TABLE border cellpadding=5 cellspacing=0 bordercolor=#545F81 width=400>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER WIDTH=100 bgcolor=#B3BBCD><FONT SIZE=2>이 름</FONT></TD>

        <TD WIDTH=300><FONT SIZE=2>$name</TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>아이디</FONT></TD>

        <TD><FONT SIZE=2>$id</TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>E-Mail</FONT></TD>

        <TD><FONT SIZE=2>$email</TD>

</TR>

 

</TABLE><br>

<TABLE WIDTH=400>

<TR>

        <TD ALIGN=CENTER><INPUT TYPE=BUTTON VALUE='로그인' onclick='location=\"login.html\";'></TD>

</TR>

</TABLE>";

}

?>

 

 

 

 

파일명 : check_id.html

<html>

<head>

   <title>Lee LAB - 아이디 중복 체크</title>

   <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">

 

   <style type="text/css">

   <!--

   a:link,a:visited,a:active {

      text-decoration : none;

   }

   a:hover {

      text-decoration : underline;

      color : red;

   }

   TABLE, TD, TR, TH {

      font-size : 10pt;

   }

   //-->

   </style>

   

   <script language="javascript">

   <!--

   function replace_id() {

      opener.document.registerform.id.select();

      self.close();

   }

   //-->

   </script>

</head>

   

<body bgColor="lightyellow">

 

<?

include "../user_function.html";

include "../dbconn.html";

 

$result = mysql_query("SELECT count(id) FROM member WHERE id = '$id'");

if (!$result) {

   error("QUERY_ERROR");

   exit;

}

$rows = mysql_result($result,0,0);

if ($rows || $rows1) {

?>

   <form>

   <table width="230" border="0" cellspacing="5" align="center">

   <tr>

      <td align="center">

      신청하신 아이디는 <br><font color="red">이미 등록</font>되어 있습니다! <p>

      <b>다른 아이디로 신청</b>하여 주십시오.

      </td>

   </tr>

   <tr>

      <td align="center">

      <font size=2>

      <input type="button" onClick="replace_id()" value="닫기">

      </font>

      </td>

   </tr>

   </table>

   </form>

<?

} else {

?>

   <form>

   <table width="230" border="0" cellspacing="5" align="center">

   <tr>

      <td align="center">

      신청하신 아이디는<br> 등록되어 있지 않으므로 <br><font color="red">사용가능</font>합니다.

      </td>

   </tr>

   <tr>

      <td align="center" align="center">

      <font size=2>

      <input type="button" onClick="self.close()" value="이 아이디로 신청합니다.">

      </font>

      </td>

   </tr>

   </table>

   </form>

<?

}

?>

 

</body>

</html>

 

 

 

2. 로그인, 로그아웃

파일명 : login.html

 

<HTML>

<HEAD>

<TITLE> LeeLAB 회원 인증 - 로그인 화면 </TITLE>

</HEAD>

 

<BODY BGCOLOR="#FFFFFF">

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 회원 인증 ]</FONT><BR>

 

<FORM METHOD=POST ACTION=login_process.html NAME=loginform>

<TABLE border cellpadding=3 cellspacing=0 bordercolor=#545F81 width=400>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>아이디</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=TEXT NAME=id SIZE=15 MAXLENGTH=15></TD>

</TR>

<TR BGCOLOR=white>

        <TD ALIGN=CENTER bgcolor=#B3BBCD><FONT SIZE=2>비밀번호</FONT></TD>

        <TD><FONT SIZE=2><INPUT TYPE=PASSWORD NAME=passwd SIZE=15 MAXLENGTH=30></TD>

</TR>

 

</TABLE><br>

<TABLE WIDTH=400>

<TR>

        <TD ALIGN=CENTER><INPUT TYPE=submit VALUE='로그인' ></TD>

</TR>

</TABLE>

</FORM>

 

</BODY>

</HTML>

 

파일명 : login_process.html

<?

include "./user_function.html";

include "./dbconn.html";

 

if($id && $passwd) {

        if(!$id) {

        echo "

                <SCRIPT>

                alert('아이디를 입력하여 주세요.');

                history.go(-1);

                </SCRIPT>";

        exit;

        }

        else if(!$passwd) {

        echo "

                <SCRIPT>

                alert('비밀번호를 입력하여 주세요.');

                history.go(-1);

                </SCRIPT>";

        exit;

        }

        else {

        $query = "SELECT id,name,email,tel,address FROM member WHERE id='$id' AND passwd='$passwd'";

        $result = mysql_query($query);

 

                if(!$result) {

                   $errNO = mysql_errno($dbconn);

                   $errMSG = mysql_error($dbconn);

 

                   echo("에러코드 $errNO : $errMSG<br>");

                   exit;

                }

 

                $total_record = mysql_num_rows($result);

        if(!$total_record) {

                echo "

                                <SCRIPT>

                                alert('아이디 또는 암호 오류.');

                                history.go(-1);

                                </SCRIPT>";

                exit;

        }

                else {

                        $row = mysql_fetch_object($result);

 

                        session_start();

 

                        session_register("user_id");

                        session_register("user_logindate");

 

                        $user_id = $row->id;

 

                    $logindate = time();

                        $user_logindate = $logindate;

 

                        $query  = "UPDATE member SET logindate = $logindate WHERE id = '$id'";  

                    $result = mysql_query($query);

                    if(!$result) {

                           error("QUERY_ERROR");

                            exit;

                    }

            echo "

                                <SCRIPT>

                                top.location.replace('./');

                                </SCRIPT>";

           exit;

 

                }

 

        }

}

?>

 

파일명 : logout.html

<?

        session_start();

        $user_id = null;

        $HTTP_SESSION_VARS["user_id"] = null;

        $user_logindate = null;

        $HTTP_SESSION_VARS["user_logindate"] = null;

 

    echo ("<meta http-equiv='Refresh' content='0; URL=./'>");

?>

 

3. 메뉴 수정하기

파일명 ; menu.html

<?

session_start();

?>

<HTML>

<HEAD>

<TITLE> 관리자 - 메뉴 </TITLE>

</HEAD>

    <style type="text/css">

   <!--

   a:link,a:visited,a:active {

      text-decoration : none; font-size: 10pt;

   }

   a:hover {

      text-decoration : underline; font-size: 10pt;

      color : red;

   }

   //-->

   </style>

 

<BODY BGCOLOR="#EEEEEE">

<br>

<?

if($user_id) {

        echo("<center><font size=2>$user_id 님께서<br>접속하였습니다.</font><br>");

?>

   <A HREF="./logout.html" target="_top">접속종료</A><p></center>

<?}else {?>

  <LI> <A HREF="./login.html" target="bookshop-main-detail">로그인</A><br>

  <LI> <A HREF="./register/registerform.html" target="bookshop-main-detail">회원가입</A><p>

<?}?>

  <LI> <A HREF="./" target="_top">홈으로</A><p>

  <LI> <A HREF="list.html?part=컴퓨터" target="bookshop-main-detail">컴퓨터</A>

  <LI> <A HREF="list.html?part=소설" target="bookshop-main-detail">소설</A><p>

 

  <LI> <A HREF="list_bag.html" target="bookshop-main-detail">장바구니보기</A>

</BODY>

</HTML>

 

[목차]

개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.