<?php
session_start();

// 1. Database Settings
// cPanel usually uses 'localhost' as the host.
$host = 'localhost';
$db   = 'monara_ratings_db'; 
$user = 'monara_ratings_user'; 
$pass = '.{L*tHx@O9MR'; 

try {
    $pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass);
    // Set error mode to see database issues during development
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}

// 2. Path Management (Fixed for HTTPS and Subfolders)
// Detect if the server is using HTTPS (SSL)
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";

// Hardcoded specifically for your test environment to prevent path errors
$base_url = $protocol . "test.athavaneng.com/teledrama_rating/";

define('BASE_URL', $base_url);

// 3. Helper Functions
function checkLogin() {
    if (!isset($_SESSION['user_id'])) {
        // Use BASE_URL here to ensure redirect works from subfolders
        header("Location: " . BASE_URL . "index.php");
        exit();
    }
}
?>