<?php
$baseHref = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
function getTrackingUrl(): string
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://server.4markets.net/api/v2/offers/tracking-domain");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Referer: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
    ]);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($httpCode != 200) {
        return "";
    }
    if (empty($response)) {
        return "";
    }

    $responseTrackingDomainJson = json_decode($response);

    if (empty($responseTrackingDomainJson)) {
        return "";
    }

    return $responseTrackingDomainJson->details->endpoint;
}

$trackingUrl = getTrackingUrl();
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <title>BitQT <?= date("Y"); ?></title>
    <base href="<?= $baseHref; ?>">
    <link rel="shortcut icon" href="images/87xBfC4_8rkECpC.ico" type="image/x-icon">
    <link href="css/site.css" rel="stylesheet" type="text/css"/>
    <script type='text/javascript' src="js/jquery.min.js"></script>
    <link rel="stylesheet" href="css/swiper-bundle.css"/>
    <link rel="stylesheet" href="css/ion.rangeSlider.min.css"/>
    <link rel="stylesheet" href="css/custom-styles.css">
    <link rel="stylesheet" href="css/intgrtn.css">





