<?php
ob_start();
session_start();

if (isset($_SESSION['user_id'])) {
    $user_id = $_SESSION['user_id'];
    $session = $_SESSION['user_id'];
} else {
    $user_id = null;
    $session = null;
}


$host = 'localhost';
$dbname = 'mogobeti';
$username = 'mogobeti';
$password = 'Hakan55@';
$charset = 'utf8mb4';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=$charset", $username, $password, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, 
        PDO::ATTR_EMULATE_PREPARES => false,
        PDO::ATTR_PERSISTENT => true
    ]);


} catch (PDOException $e) {
    die("Veritabanı bağlantı hatası: " . $e->getMessage());
}



$stmt1 = $pdo->prepare("SELECT * FROM game_api_settings WHERE name = 'indexpopulercasino'");
$stmt1->execute();
$casino_setting = $stmt1->fetch(PDO::FETCH_ASSOC);

$stmt2 = $pdo->prepare("SELECT * FROM game_api_settings WHERE name = 'indexpopulercanlicasino'");
$stmt2->execute();
$canli_setting = $stmt2->fetch(PDO::FETCH_ASSOC);

$stmt3 = $pdo->prepare("SELECT * FROM game_api_settings WHERE name = 'indexcrash'");
$stmt3->execute();
$crash_setting = $stmt3->fetch(PDO::FETCH_ASSOC);

$web_settings = $pdo->prepare("SELECT * FROM settings");
$web_settings->execute();
$web = $web_settings->fetch(PDO::FETCH_ASSOC);


$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";

$host = $_SERVER['HTTP_HOST'];

// Host'u parçala
$parts = explode('.', $host);

// Son iki parçayı al → domain + tld
$domain = implode('.', array_slice($parts, -2));

// Yeni host oluştur
$newHost = 'm.' . $domain;

$base_url = $protocol . '://' . $newHost . '/';


$session_user = $pdo->prepare("SELECT * FROM users WHERE user_id = :user_id");
$session_user->execute(['user_id' => $user_id]);
$user = $session_user->fetch(PDO::FETCH_ASSOC);




?>
