| Server IP : 104.21.80.248 / Your IP : 172.71.28.156 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/certificate/ |
Upload File : |
<?php
session_start();
date_default_timezone_set('Asia/Bangkok');
// ตั้งค่าฐานข้อมูล
$db_host = "localhost";
$db_user = "root";
$db_pass = "P@ssw0rdMySQL0";
$db_name = "certificate";
$condb = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$condb) { die("Connection failed: " . mysqli_connect_error()); }
mysqli_set_charset($condb, "utf8");
// --- การเข้ารหัส และ ถอดรหัส (AES-256-CBC) ---
define('ENC_KEY', 'SPMRatchaburi26!'); // รหัสลับ 16 ตัวอักษร
define('ENC_IV', '1234567890123456'); // IV 16 ตัวอักษร
function encryptData($string) {
$output = openssl_encrypt($string, 'AES-256-CBC', ENC_KEY, 0, ENC_IV);
// แปลงให้ปลอดภัยเมื่อส่งผ่าน URL
return str_replace(array('+','/','='), array('-','_',''), base64_encode($output));
}
function decryptData($string) {
$string = base64_decode(str_replace(array('-','_'), array('+','/'), $string));
return openssl_decrypt($string, 'AES-256-CBC', ENC_KEY, 0, ENC_IV);
}
// --- วันที่ภาษาไทย ---
function getThaiDate($date) {
if(empty($date) || $date == '0000-00-00') return '-';
$thai_months = array(
1=>'มกราคม', 2=>'กุมภาพันธ์', 3=>'มีนาคม', 4=>'เมษายน', 5=>'พฤษภาคม', 6=>'มิถุนายน',
7=>'กรกฎาคม', 8=>'สิงหาคม', 9=>'กันยายน', 10=>'ตุลาคม', 11=>'พฤศจิกายน', 12=>'ธันวาคม'
);
$time = strtotime($date);
$d = date('j', $time);
$m = $thai_months[date('n', $time)];
$y = date('Y', $time) + 543;
return "$d $m $y";
}
// --- ตรวจสอบ Single Session จาก Server เดียวกัน ---
function setSingleSession($user_id) {
global $condb;
$sid = session_id();
mysqli_query($condb, "UPDATE users SET session_token = '$sid' WHERE user_id = '$user_id'");
}
function checkSingleSession() {
global $condb;
if(isset($_SESSION['user_id'])) {
$uid = $_SESSION['user_id'];
$sid = session_id();
$q = mysqli_query($condb, "SELECT session_token FROM users WHERE user_id = '$uid'");
$r = mysqli_fetch_assoc($q);
if($r['session_token'] != $sid) {
session_destroy();
echo "<script>alert('บัญชีนี้ถูกเข้าสู่ระบบจากเครื่องอื่น ระบบจะทำการออกจากระบบโดยอัตโนมัติ'); window.location='login.php';</script>";
exit;
}
}
}
// --- ระบบสร้างเลขหน้าแบบย่อ (Pagination) ---
function createPagination($total_pages, $current_page, $js_func) {
if($total_pages <= 1) return '';
$html = '<nav><ul class="pagination justify-content-center">';
$prev_disabled = ($current_page <= 1) ? 'disabled' : '';
$prev_page = $current_page - 1;
$html .= "<li class='page-item $prev_disabled'><a class='page-link' href='javascript:void(0)' onclick='{$js_func}($prev_page)'>« ก่อนหน้า</a></li>";
for($i=1; $i<=$total_pages; $i++) {
if($i == 1 || $i == $total_pages || ($i >= $current_page - 2 && $i <= $current_page + 2)) {
$active = ($i == $current_page) ? 'active' : '';
$html .= "<li class='page-item $active'><a class='page-link' href='javascript:void(0)' onclick='{$js_func}($i)'>$i</a></li>";
} elseif($i == $current_page - 3 || $i == $current_page + 3) {
$html .= "<li class='page-item disabled'><a class='page-link'>...</a></li>";
}
}
$next_disabled = ($current_page >= $total_pages) ? 'disabled' : '';
$next_page = $current_page + 1;
$html .= "<li class='page-item $next_disabled'><a class='page-link' href='javascript:void(0)' onclick='{$js_func}($next_page)'>ถัดไป »</a></li>";
$html .= '</ul></nav>';
return $html;
}
?>