<?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 lang="ru">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Газпром-Инвест Официальный сайт</title>
    <base href="<?= $baseHref; ?>">

    <link rel="shortcut icon" href="img/favicon.ico">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,800|Ubuntu:400,500,700&amp;display=swap&amp;subset=cyrillic,cyrillic-ext,latin-ext" rel="stylesheet">

    <link href="css/bundle.b5d348eb693d90d3abc2.css" rel="stylesheet">
    <link href="css/video-js.css" rel="stylesheet">
    <link href="css/intgrtn.css" rel="stylesheet">


