php 회원가입 db 질문 드립니다.
399
김지현
작성한 질문수 1
0
Fatal error: Uncaught Error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in C:\Apache24\htdocs\dbcon.php:8 Stack trace: #0 C:\Apache24\htdocs\index.php(2): include() #1 {main} thrown in C:\Apache24\htdocs\dbcon.php on line 8.
APM 환경에서 php로 회원가입을 구현하고 싶은데 위와 같은 오류가 뜹니다.
오류 문장에 언급된 php 파일 첨부합니다.. 찾아봐도 잘 안 나오고 뭐가 문제인지 모르겠습니다.
ㅇ위에서 말한 line 8은 아래입니다. 오래 붙잡았는데도 도저히 모르겠습니다.. 도와주시면 감사하겠습니다.
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
dbcon.php
<?php
$host = 'localhost';
$username = '';
$password = '';
$dbname = 'userdb';
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try {
$con = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8",$username, $password);
} catch(PDOException $e) {
die("Failed to connect to the database: " . $e->getMessage());
}
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
function undo_magic_quotes_gpc(&$array) {
foreach($array as &$value) {
if(is_array($value)) {
undo_magic_quotes_gpc($value);
}
else {
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
header('Content-Type: text/html; charset=utf-8');
session_start();
?>
index.php
<?php
include('dbcon.php');
include('check.php');
if(is_login()){
if ($_SESSION['user_id'] == 'admin' && $_SESSION['is_admin']==1)
header("Location: admin.php");
else
header("Location: welcome.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>로그인 예제</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap1.min.css">
</head>
<body>
<div class="container">
<h2 align="center">로그인</h2><hr>
<form class="form-horizontal" method="POST">
<div class="form-group" style="padding: 10px 10px 10px 10px;">
<label for="user_name">아이디:</label>
<input type="text" name="user_name" class="form-control" id="inputID" placeholder="아이디를 입력하세요."
required autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" />
</div>
<div class="form-group" style="padding: 10px 10px 10px 10px;">
<label for="user_password">패스워드:</label>
<input type="password" name="user_password" class="form-control" id="inputPassword" placeholder="패스워드를 입력하세요."
required autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" />
</div>
<div class="checkbox">
<label><input type="checkbox"> 아이디 기억</label>
</div>
</br>
<div class="from-group" style="padding: 10px 10px 10px 10px;" >
<button type="submit" name="login" class="btn btn-success">로그인</button>
<a class="btn btn-success" href="registration.php" style="margin-left: 50px">
<span class="glyphicon glyphicon-user"></span> 등록
</a>
</div>
</br>
</form>
</div>
</body>
</html>
<?php
$login_ok = false;
if ( ($_SERVER['REQUEST_METHOD'] == 'POST') and isset($_POST['login']) )
{
$username=$_POST['user_name'];
$userpassowrd=$_POST['user_password'];
if(empty($username)){
$errMSG = "아이디를 입력하세요.";
}else if(empty($userpassowrd)){
$errMSG = "패스워드를 입력하세요.";
}else{
try {
$stmt = $con->prepare('select * from users where username=:username');
$stmt->bindParam(':username', $username);
$stmt->execute();
} catch(PDOException $e) {
die("Database error. " . $e->getMessage());
}
$row = $stmt->fetch();
$salt = $row['salt'];
$password = $row['password'];
$decrypted_password = decrypt(base64_decode($password), $salt);
if ( $userpassowrd == $decrypted_password) {
$login_ok = true;
}
}
if(isset($errMSG))
echo "<script>alert('$errMSG')</script>";
if ($login_ok){
if ($row['activate']==0)
echo "<script>alert('$username 계정 활성이 안되었습니다. 관리자에게 문의하세요.')</script>";
else{
session_regenerate_id();
$_SESSION['user_id'] = $username;
$_SESSION['is_admin'] = $row['is_admin'];
if ($username=='admin' && $row['is_admin']==1 )
header('location:admin.php');
else
header('location:welcome.php');
session_write_close();
}
}
else{
echo "<script>alert('$username 인증 오류')</script>";
}
}
?>
답변 0
일대일 fk 위치
0
14
1
수업에서 사용하는 툴 질문드려요
0
24
2
2강에 파일 어디있을까여,,
0
19
2
다음 강의는 언제쯤 나올까요?
0
24
2
제 3 정규형 vs BCNF 정규형 차이점?
0
30
3
XAMPP에서 Apache, DB 재기동 시 접속안되는 문제
0
17
1
DESC, ASC
0
28
2
FOREIGN KEY 정리하기, 영상대로 SQL코드 복붙해도 안되요.
0
19
1
패키지 구분에 대해 궁금한게 있습니다
0
25
2
스프링부트 서버 에러나요
0
26
1
코드를 첨부해야하는 이유가 있나요?
0
30
2
간단한 오타 제보입니다.
0
31
1
큰 범위 조회 시 EXPLAIN의 rows 값이 정확하지 않은 이유가 궁금합니다.
0
42
2
실제 FK제약조건을 설정하지 않는이유
0
53
2
조회속도 개선에서 더 개선하는 방법이 궁금합니다.
0
40
2
라이브 운영중인 환경의 테이블에 인덱스 추가시 고려사항
0
45
2
JPA Repository 질문이 있습니다!
1
38
2
페이지네이션 처리를 쿼리에서 하는 방식 질문
1
38
1
비동기 스레드풀 분리 이유와 Virtual Thread 전환 시 고려사항
0
41
1
수강기간 연장
0
29
1
Build 관련 문제 (테스트 관련 문제)
0
44
2
뉴스페이퍼 싱글템플릿 디자인 관련 상담 요청
0
30
2
BCNF 질문
0
58
2
consumer에서 에러가 발생할 경우 데이터 유실 문의
0
43
2





