개발관련
PHP 회원가입 구현
<OOO>
2020. 8. 30. 19:54
728x90
회원가입 시 회원가입한 ip까지 저장하게끔 만들었다.
<?php
include_once "./board/dbconf.php";
$con = mysqli_connect($db_host,$db_user,$db_pw,$db_db);
$ip = $_SERVER['REMOTE_ADDR'];
$name = strip_tags($_POST['name']);
$id = strip_tags($_POST['userid']);
$pw = strip_tags($_POST['pw']);
$pw2 = strip_tags($_POST['pw2']);
$name = mysqli_real_escape_string($con, $name);
$id = mysqli_real_escape_string($con, $id);
$pw = mysqli_real_escape_string($con, $pw);
$pw2 = mysqli_real_escape_string($con, $pw2);
if($name == NULL || $id == NULL || $pw == NULL || $pw2 == NULL)
{
echo ("<script>alert('빈 칸이 있습니다. 모두 채워주세요.')</script>");
echo ("<script>history.back();</script>");
exit;
}
if($pw != $pw2)
{
echo ("<script>alert('비밀번호가 맞지 않습니다.')</script>");
echo ("<script>history.back();</script>");
exit;
}
$sql = "select id from users where id = '".$id."'";
$result = mysqli_query($con, $sql);
$member = mysqli_num_rows($result);
if($member == 1)
{
echo ("<script>alert('이미 사용중인 아이디 입니다.')</script>");
echo ("<script>history.back();</script>");
exit;
}
if(strlen($pw <= 8) || strlen($pw <= 20))
{
echo ("<script>alert('비밀번호는 8~20자리로 설정하여 주십시오.</script>");
echo ("<script>history.back();</script>");
}
$pass = password_hash($pw, PASSWORD_DEFAULT);
$insert = "insert into users(name,id,password,ip) values ('$name', '$id', '$pass','$ip')";
$query = mysqli_query($con, $insert);
if(!$query)
{
echo ("<script>alert('회원가입 실패')</script>");
echo ("<script>history.back();</script>");
exit;
}
else
{
echo ("<script>alert('회원가입 성공')</script>");
header("Location:./login");
exit;
}
mysqli_close($con);
?>