<?php
$session_lifetime = 60 * 60 * 24 * 365 * 10; // 10 বছর

ini_set('session.gc_maxlifetime', $session_lifetime);
ini_set('session.cookie_lifetime', $session_lifetime);
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_httponly', 1);

$is_https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');

session_set_cookie_params([
    'lifetime' => $session_lifetime,
    'path' => '/',
    'secure' => $is_https,
    'httponly' => true,
    'samesite' => 'Lax'
]);

session_start();
date_default_timezone_set('Asia/Dhaka');


$host = "localhost";
$dbname = "nextgens_clients_website"; 
$username = "nextgens_clients_websites"; 
$password = "RAHMATdewan..11";

// Database Connection
$conn = new mysqli($host, $username, $password, $dbname);
$conn->query("SET time_zone = '+06:00'");


// Check Connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Function to sanitize input
function clean($data) {
    global $conn;
    return mysqli_real_escape_string($conn, htmlspecialchars(strip_tags(trim($data))));
}

function sendSMS($number, $message) {
    $url = "http://bulksmsbd.net/api/smsapi";
    $api_key = "dlKA6EItJEyxDhwyGBpU";
    $senderid = "8809612364133";

    $number = preg_replace('/[^0-9]/', '', $number);

    if (substr($number, 0, 2) !== "88") {
        $number = "88" . $number;
    }

    $data = [
        "api_key" => $api_key,
        "type" => "unicode",
        "number" => $number,
        "senderid" => $senderid,
        "message" => $message
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);

    if ($error) {
        return "CURL_ERROR: " . $error;
    }

    return $response;
}

?>