php 세션 유지 로직 수정

This commit is contained in:
Lectom C Han
2026-02-05 13:15:54 +09:00
parent 1cdfe27ef7
commit d6a4443351
34 changed files with 116 additions and 601 deletions

View File

@@ -1,261 +0,0 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: application/json; charset=utf-8');
/* =========================
로그인 / 권한 가드
========================= */
require_once __DIR__ . '/adm_guard.php';
require_once __DIR__ . '/db_conn.php';
/* =========================
세션 기준 값 (중요)
========================= */
$login = $_SESSION['login'];
$auth_bc = $login['auth_bc']; // 권한코드
$member_id = $login['member_id']; // 회사ID
/* =========================
입력
========================= */
$input = json_decode(file_get_contents('php://input'), true) ?? [];
$action = $_GET['action'] ?? $input['action'] ?? 'list';
/* =========================
권한 플래그
========================= */
$isAdmin = in_array($auth_bc, ['BS100100','BS100200','BS100300'], true);
try {
switch ($action) {
/* =========================
0. 공통코드 조회 (콤보)
========================= */
case 'base_code':
$main_cd = $_GET['main_cd'] ?? $input['main_cd'] ?? '';
if (!$main_cd) {
throw new Exception('main_cd가 필요합니다.');
}
$stmt = $pdo->prepare("
SELECT *
FROM kngil.fn_base_cd(:main_cd)
");
$stmt->execute([
':main_cd' => $main_cd
]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'status' => 'success',
'items' => $rows // [{id, text}]
]);
break;
/* =========================
1. 사용자 목록 조회
========================= */
case 'list':
$schType = $_GET['sch_type'] ?? '';
$schKeyword = $_GET['sch_keyword'] ?? '';
$schUseYn = $_GET['sch_use_yn'] ?? '';
// 기본값
$sch_id = '';
$sch_nm = '';
$sch_dept = '';
if ($schKeyword !== '') {
switch ($schType) {
case 'id':
$sch_id = $schKeyword;
break;
case 'name':
$sch_nm = $schKeyword;
break;
case 'dept':
$sch_dept = $schKeyword;
break;
default: // 전체
$sch_id = $schKeyword;
$sch_nm = $schKeyword;
$sch_dept = $schKeyword;
}
}
$sql = "
SELECT *
FROM kngil.sp_users_r(
:member_id,
:user_nm,
:dept_nm,
:use_yn
);
";
$stmt = $pdo->prepare($sql);
$stmt->execute([
':member_id' => $member_id,
':user_nm' => $_GET['user_nm'] ?? '',
':dept_nm' => $_GET['dept_nm'] ?? '',
':use_yn' => $_GET['use_yn'] ?? ''
]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$i = 1;
foreach ($rows as &$r) {
$r['recid'] = $i++;
}
echo json_encode([
'status' => 'success',
'member_id' => $member_id,
'records' => $rows
]);
break;
/* =========================
2. 사용자 저장
========================= */
case 'save':
$inserts = $input['inserts'] ?? [];
$updates = $input['updates'] ?? [];
if (!$inserts && !$updates) {
throw new Exception('저장할 데이터가 없습니다.');
}
$pdo->beginTransaction();
// INSERT
if ($inserts) {
$stmtI = $pdo->prepare("
SELECT kngil.sp_users_i(
:member_id,:user_id,:user_pw,:user_nm,:dept_nm,
:posit_nm,:tel_no,:email,:auth_bc,:use_yn,:rmks,:cid
)
");
foreach ($inserts as $r) {
$stmtI->execute([
':member_id' => $member_id,
':user_id' => $r['user_id'],
':user_pw' => $r['user_pw'] ?? '0000',
':user_nm' => $r['user_nm'],
':dept_nm' => $r['dept_nm'],
':posit_nm' => $r['posit_nm'] ?? '',
':tel_no' => $r['tel_no'],
':email' => $r['email'],
':auth_bc' => $r['auth_bc'],
':use_yn' => $r['use_yn'],
':rmks' => $r['rmks'] ?? '',
':cid' => $r['cid'] ?? 'SYSTEM'
]);
}
}
// UPDATE
if ($updates) {
$stmtU = $pdo->prepare("
SELECT kngil.sp_users_u(
:member_id,:user_id,:user_pw,:user_nm,:dept_nm,
:posit_nm,:tel_no,:email,:auth_bc,:use_yn,:rmks,:mid
)
");
foreach ($updates as $r) {
$stmtU->execute([
':member_id' => $member_id,
':user_id' => $r['user_id'],
':user_pw' => null,
':user_nm' => $r['user_nm'],
':dept_nm' => $r['dept_nm'],
':posit_nm' => $r['posit_nm'] ?? '',
':tel_no' => $r['tel_no'],
':email' => $r['email'],
':auth_bc' => $r['auth_bc'],
':use_yn' => $r['use_yn'],
':rmks' => $r['rmks'] ?? '',
':mid' => $r['mid'] ?? 'SYSTEM'
]);
}
}
$pdo->commit();
echo json_encode(['status'=>'success']);
break;
/* =========================
3. 사용자 삭제 (비활성)
========================= */
case 'delete':
$ids = $input['ids'] ?? [];
if (!$ids) throw new Exception('삭제 대상이 없습니다.');
$sql = "SELECT kngil.sp_users_d(:member_id, :user_id)";
$stmt = $pdo->prepare($sql);
foreach ($ids as $uid) {
$stmt->execute([
':member_id' => $member_id,
':user_id' => $uid
]);
}
echo json_encode(['status'=>'success']);
break;
/* =========================
4. 회원 총 구매 면적 조회
========================= */
case 'total_area':
$sql = "
SELECT COALESCE(SUM(sum_area), 0) AS total_area
FROM kngil.sp_buy_item_history_r(:member_id, '', NULL, NULL)
";
$stmt = $pdo->prepare($sql);
$stmt->execute([
':member_id' => $member_id
]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode([
'status' => 'success',
'member_id' => $member_id,
'total_area' => (int)$row['total_area']
]);
break;
default:
throw new Exception('잘못된 요청');
}
} catch (Exception $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => $e->getMessage()
]);
}

View File

@@ -1,160 +0,0 @@
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
header('Content-Type: application/json');
$data = json_decode(file_get_contents('php://input'), true);
$action = $data['action'] ?? '';
/* =================================================
아이디 중복확인 (fn_user_id_check 사용)
================================================= */
if ($action === 'check_id') {
$userId = trim($data['userId'] ?? '');
if (!preg_match('/^[a-zA-Z][a-zA-Z0-9]{3,11}$/', $userId)) {
echo json_encode([
'available' => false,
'message' => '아이디 형식 오류'
]);
exit;
}
$stmt = $pdo->prepare("
SELECT kngil.fn_user_id_check(:user_id)
");
$stmt->execute([
':user_id' => $userId
]);
$result = trim($stmt->fetchColumn());
if (strpos($result, 'SUCCESS') === 0) {
echo json_encode([
'available' => true,
'message' => '사용 가능한 아이디입니다.'
]);
} else {
echo json_encode([
'available' => false,
'message' => '이미 존재하는 아이디입니다.'
]);
}
exit;
}
/* =================================================
1. 필수값 검증
================================================= */
$required = [
'memberType', // 회원유형
'userId',
'password',
'userName',
'email',
'phone'
];
foreach ($required as $k) {
if (empty($data[$k])) {
echo json_encode([
'success' => false,
'message' => '필수 항목이 누락되었습니다.'
]);
exit;
}
}
/* =================================================
2. 회원유형 → co_bc 매핑
================================================= */
/*
기업회원 : '1'
개인회원 : '2'
→ 실제 코드값은 여기서 통제
*/
$co_bc = ($data['memberType'] === '1')
? 'CB100100' // 기업
: 'CB100200'; // 개인
/* =================================================
3. 비밀번호 규칙 + 암호화
================================================= */
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*]).{12,}$/', $data['password'])) {
echo json_encode([
'success' => false,
'message' => '비밀번호 규칙이 올바르지 않습니다.'
]);
exit;
}
$hashedPw = password_hash($data['password'], PASSWORD_DEFAULT);
/* =================================================
4. 이메일 형식
================================================= */
if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
echo json_encode([
'success' => false,
'message' => '이메일 형식 오류'
]);
exit;
}
/* =================================================
5. 프로시저 호출
================================================= */
try {
$stmt = $pdo->prepare("
SELECT kngil.sp_member_i(
:p_co_bc,
:p_member_id,
:p_user_pw,
:p_member_nm,
:p_email,
:p_tel_no,
:p_co_nm,
:p_dept_nm,
:p_cid
) AS result
");
$stmt->execute([
':p_co_bc' => $co_bc,
':p_member_id' => $data['userId'],
':p_user_pw' => $hashedPw,
':p_member_nm' => $data['userName'],
':p_email' => $data['email'],
':p_tel_no' => $data['phone'],
':p_co_nm' => $data['company'] ?? null,
':p_dept_nm' => $data['department'] ?? null,
':p_cid' => $data['userId']
]);
$result = $stmt->fetchColumn();
if ($result === 'SUCCESS') {
echo json_encode([
'success' => true
]);
} else {
echo json_encode([
'success' => false,
'message' => $result
]);
}
} catch (Exception $e) {
echo json_encode([
'success' => false,
'message' => '서버 오류'
]);
}
echo json_encode([
'success' => false,
'message' => 'Invalid action'
]);
exit;

View File

@@ -1,179 +0,0 @@
<?php
/**
* Sentinel SMS 매직링크 테스트 (PHP)
* - phoneNumber: 01086270921 (고정)
* - system: kngil
* - secret_key: MY_SECRET_KEY
*/
header('Content-Type: application/json; charset=utf-8');
/* =========================
설정값
========================= */
$AUTH_SERVER = 'http://61.98.205.242:8075';
$SYSTEM = 'kngil';
$SECRET_KEY = '9f3b2e7a0a4f1f25c41c8c2367d04d54a89a2a5b2b189d63a99a0b874db4b27f';
$PHONE = '01086270921';
/* =========================
JWT 생성 (HS256)
========================= */
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function create_jwt($payload, $secret) {
$header = ['alg'=>'HS256','typ'=>'JWT'];
$segments = [];
$segments[] = base64url_encode(json_encode($header));
$segments[] = base64url_encode(json_encode($payload));
$signing_input = implode('.', $segments);
$signature = hash_hmac('sha256', $signing_input, $secret, true);
$segments[] = base64url_encode($signature);
return implode('.', $segments);
}
/* =========================
cURL 요청 함수
========================= */
function curl_json($url, $method='GET', $headers=[], $body=null) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $body,
CURLOPT_TIMEOUT => 10
]);
$response = curl_exec($ch);
$err = curl_error($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($err) {
throw new Exception($err);
}
return [$code, $response];
}
/* =========================
MODE 분기
========================= */
$mode = $_GET['mode'] ?? 'request';
try {
/* =========================
1⃣ 매직링크 발급 요청
========================= */
if ($mode === 'request') {
// JWT payload (3분 유효)
$payload = [
'system' => $SYSTEM,
'iat' => time(),
'exp' => time() + 180
];
$jwt = create_jwt($payload, $SECRET_KEY);
[$code, $res] = curl_json(
$AUTH_SERVER.'/auth/sentinel',
'POST',
[
'Authorization: Bearer '.$jwt,
'Content-Type: application/json'
],
json_encode([
'phoneNumber' => $PHONE
])
);
echo json_encode([
'step' => 'sentinel_request',
'http_code' => $code,
'response' => json_decode($res, true)
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;
}
/* =========================
2⃣ 매직링크 상태 확인
========================= */
if ($mode === 'status') {
$token = $_GET['token'] ?? '';
if (!$token) {
throw new Exception('token 필요');
}
$payload = [
'system' => $SYSTEM,
'iat' => time(),
'exp' => time() + 180
];
$jwt = create_jwt($payload, $SECRET_KEY);
[$code, $res] = curl_json(
$AUTH_SERVER.'/auth/status?token='.$token,
'GET',
[
'Authorization: Bearer '.$jwt
]
);
$data = json_decode($res, true);
// 🔴 여기부터가 "로그인 처리"
if (!empty($data['loggedIn'])) {
$stmt = $pdo->prepare("
SELECT member_id, user_id, user_nm, auth_bc
FROM kngil.users
WHERE REPLACE(tel_no, '-', '') = :phone
AND use_yn = 'Y'
LIMIT 1
");
$stmt->execute([':phone' => $PHONE]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
throw new Exception('해당 번호로 등록된 사용자 없음');
}
$_SESSION['login'] = [
'member_id' => $user['member_id'],
'user_id' => $user['user_id'],
'user_nm' => $user['user_nm'],
'auth_bc' => $user['auth_bc']
];
echo json_encode([
'status' => 'success',
'message' => '자동 로그인 완료'
]);
exit;
}
echo json_encode([
'status' => 'pending'
]);
exit;
}
} catch (Exception $e) {
echo json_encode([
'error' => true,
'message' => $e->getMessage()
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}

View File

@@ -1,4 +1,6 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/adm_guard.php';
?>
<!DOCTYPE html>

View File

@@ -1,4 +1,6 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/adm_guard.php';
?>
<!DOCTYPE html>

View File

@@ -1,4 +1,6 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/adm_guard.php';
?>
<!DOCTYPE html>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_agreement" role="dialog" aria-labelledby="agreement_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_cancel" role="dialog" aria-labelledby="mypage03_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_join" role="dialog" aria-labelledby="join_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_join2" role="dialog" aria-labelledby="join_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_join3" role="dialog" aria-labelledby="join_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_login2" role="dialog" aria-labelledby="login_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_mypage01" role="dialog" aria-labelledby="mypage01_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_mypage02" role="dialog" aria-labelledby="mypage02_title" aria-modal="true" style="display:none;">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_mypage03" role="dialog" aria-labelledby="mypage03_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_mypage04" role="dialog" aria-labelledby="mypage03_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_mypage05" role="dialog" aria-labelledby="mypage03_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_mypage06" role="dialog" aria-labelledby="mypage03_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_password" role="dialog" aria-labelledby="password_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_privacy" role="dialog" aria-labelledby="privacy-title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- popup_wrap -->
<div class="popup-wrap" id="pop_search" role="dialog" aria-labelledby="search_title" aria-modal="true">
<!-- popup_in -->

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,4 +1,6 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
// 슈퍼관리자 권한 체크
?>
<!DOCTYPE html>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!-- <?php if (!empty($errors)): ?>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>

View File

@@ -1,4 +1,7 @@
<?php
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
include __DIR__ . '/layout_sales.php';
sales_layout_start("영업실적");
?>

View File

@@ -1,3 +1,7 @@
<?php
require_once __DIR__ . '/../bbs/env.php';
kngil_start_session();
?>
<!DOCTYPE html>
<html lang="ko">
<head>