<?php

// Allow from any origin
// if (isset($_SERVER['HTTP_ORIGIN'])) {
//     // should do a check here to match $_SERVER['HTTP_ORIGIN'] to a
//     // whitelist of safe domains
//     header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
//     header('Access-Control-Allow-Credentials: true');
//     header('Access-Control-Max-Age: 86400');    // cache for 1 day
// }
// Access-Control headers are received during OPTIONS requests
// if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

//     if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
//         header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");         

//     if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
//         header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

// }

//get full link
$actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
//get last part of link
if(preg_match("/\/(\d+)$/",$actual_link,$matches))
{
  $channel_id=$matches[1];
}
else { $channel_id=0; }
//send http request to server then return response

#$resp = file_get_contents("http://ts.xtream4.xyz:8080/ouoland_891579/NFA4Lknu/");
$resp = http_get("http://ts.xtream4.xyz:8080/ouoland_891579/NFA4Lknu/$channel_id");

//set headers
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
//header('Access-Control-Max-Age: 86400');

//send response
echo $resp;