File manager - Edit - /home/webapp69.cm.in.th/u69319090033/Shop/db.php
Back
<?php // Set secure session parameters before starting session ini_set('session.cookie_httponly', 1); ini_set('session.use_only_cookies', 1); if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') { ini_set('session.cookie_secure', 1); } if (session_status() === PHP_SESSION_NONE) { session_start(); } // Determine environment (Localhost XAMPP vs CLI vs Hosting Server) // Compatible with PHP 7.x and PHP 8.x (avoid str_starts_with which needs PHP 8.0+) $http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $is_cli = (php_sapi_name() === 'cli' || empty($http_host)); $is_localhost = ($is_cli || $http_host === 'localhost' || $http_host === '127.0.0.1' || strpos($http_host, 'localhost:') === 0 || strpos($http_host, '127.0.0.1:') === 0); if ($is_localhost) { // Localhost (XAMPP) Configuration $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_name = 'myshop'; } else { // Web Hosting Server Configuration $db_host = 'localhost'; $db_user = 'u69319090033'; $db_pass = '@6933'; $db_name = 'shop69319090033'; } // Create connection using MySQLi with utf8mb4 mysqli_report(MYSQLI_REPORT_OFF); // Disable exceptions to handle error manually $conn = new mysqli($db_host, $db_user, $db_pass, $db_name); if ($conn->connect_error) { error_log('DB Connection failed: ' . $conn->connect_error); // Return JSON error — safe for API endpoints if (!headers_sent()) { header('Content-Type: application/json; charset=utf-8'); } die(json_encode(['error' => 'Database connection failed.'])); } $conn->set_charset('utf8mb4'); ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings