Files
Siro/walletintaleq.intaleq.xyz/v2/main/connect.php
2026-06-16 02:52:06 +03:00

55 lines
1.8 KiB
PHP
Executable File

<?php
// Load environment variables from .env file
require_once realpath(__DIR__ . '/../vendor/autoload.php');
require_once 'load_env.php';
$envFile = '/home/intaleq-walletintaleq/env/.env';
if (!file_exists($envFile)) {
$envFile = __DIR__ . '/../.env';
}
loadEnvironment($envFile);
// Get environment variables (You don't need user/pass for JWT auth itself)
$secretKey = getenv('SECRET_KEY'); // Only need the secret key now
// --- CORS Headers ---
header("Access-Control-Allow-Origin: https://wallet.siromove.com");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); // Adjust as needed
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header('Content-Type: application/json'); // Set content type to JSON
// Handle preflight requests (OPTIONS)
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
http_response_code(200);
exit;
}
$dbname = getenv('dbname');
// --- Database Connection (Still needed for your application logic) ---
try {
$dsn = "mysql:host=localhost;dbname=$dbname;charset=utf8mb4";
$options = [
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"
];
$user = getenv('USER'); // Still used for DB connection
$pass = getenv('PASS'); // Still used for DB connection
$con = new PDO($dsn, $user, $pass, $options);
// echo $con;
// --- JWT Authentication ---
include "functions.php"; // Include the functions file
$decodedToken = authenticateJWT(); // Call the authentication function
} catch (PDOException $e) {
error_log($e->getMessage());
http_response_code(500); // Internal Server Error
echo json_encode(['error' => 'A database error occurred.']);
exit;
}
?>