<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$headerScriptRoot = dirname(__FILE__, 2);//since header.php is always in subfolder, get 1 level above
if($root == $headerScriptRoot) {
	$baseHref = '/';
} else {
	//get the first subfolder
	$baseHref = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "/", 1) + 1);
}
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="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<style class="vjs-styles-defaults">
		body {
			margin: 0;
			padding: 0;
			line-height: 1.42857143;
			font-family: 'Roboto', sans-serif;
		}
		.video-js {
			width: 300px;
			height: 150px;
		}

		.vjs-fluid {
			padding-top: 56.25%
		}
	</style>

	<title>Immediate Bitcoin</title>
	<base href="<?= $baseHref; ?>">

	<meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/css.css" rel="stylesheet">
    <link href="css/css(1).css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/style1.css" rel="stylesheet">
    <link href="css/style2.css" rel="stylesheet">
    <link href="css/videojs.css" rel="stylesheet">
	<link href="css/intgrtn.css" rel="stylesheet">
	<link rel="icon" type="image/png" href="images/favicon.png">
