PHP 비밀번호 변경하기
페이지 정보
본문
##### passwd.php #####
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html>
<head>
<title>비밀번호 변경</title>
<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>
<script type='text/javascript' language='javascript'>
function check(form)
{
if(form.name.value.length < 1)
{
alert('이름을 입력하셔야 합니다.');
form.name.focus();
return false;
}
if(form.id.value.length < 1)
{
alert('아이디를 입력하셔야 합니다.');
form.id.focus();
return false;
}
if(form.password.value.length < 4)
{
alert('비밀번호는 최소 4자이상 입력하셔야 합니다.');
form.password.focus();
return false;
}
}
</script>
</head>
<body>
<form name='form' onSubmit='return check(this);' method='post' action='passwd_or.php' enctype='multipart/form-data'>
<table width="590" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="35" bgcolor="#f7f7f7" class="contents_indent">이 름(*)</td>
<td><input type='text' class='input' name='name' value='' /></td>
</tr>
<tr>
<td width="140" height="35" bgcolor="#f7f7f7" class="contents_indent">아이디(*)</td>
<td><input type='text' class='input' name='id' value='' /></td>
</tr>
<tr>
<td height="35" bgcolor="#f7f7f7" class="contents_indent">비밀번호(*)</td>
<td><input type='text' class='input' size='15' maxlength='15' name="password" /></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type='submit' value='변경' class='input' style='cursor:pointer' />
<input type='button' value='취소' onclick='self.close()' class='input' style='cursor:pointer' />
</td>
</tr>
</table>
</form>
</body>
</html>
##### dbconfig.php #####
<?php
global $host, $user, $pw, $dbname;
$db_host = "디비서버주소";
$db_user = "아이디";
$db_pass = "비밀번호";
$db_name = "데이타베이스";
@mysqli_connect($db_host, $db_user, $pass) or die(mysqli_error());
@mysqli_select_db($db_name) or die(mysqli_error());
$dbconn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
?>
##### passwd_ok.php #####
<?php
include "dbconfig.php";
$member_id = $_POST['id'];
$member_name = $_POST['name'];
$new_pass = crypt(trim($_POST['password']));
$query = "select * from zavi_member where member_id='{$member_id}' and member_name = '{$member_name}'";
$result = mysqli_query($dbconn, $query);
$error = mysqli_num_rows($result);
//echo $error;
if($error == ""){
echo "
<script type='text/Javascript'>
<!--
alert('자료가 없습니다.\\n관리자에게 문의 하시기 바랍니다.');
history.back();
//-->
</script>
";
//echo"자료가 없습니다";
}
else {
//echo "자료가 있습니다.";
$query2 = "update zavi_member set
member_pass='{$new_pass}'
where member_id='{$member_id}' "; // 글 작성날짜 -> 필드명: date == 함수명 : now()
//echo $query2;
mysqli_query($dbconn, $query2);
echo "<script type='text/javascript'>alert('변경 하였습니다.'); self.close();</script>";
}
?>
참고자료
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_db&wr_id=132843
댓글목록
등록된 댓글이 없습니다.