public function __construct()
{
header("Access-Control-Allow-Credentials: true");
$last_host = $_SERVER['HTTP_REFERER'];
if ($last_host[4] == 's') {
preg_match("/^(https:\/\/)?([^\/]+)/i", $last_host, $matches);
header("Access-Control-Allow-Origin: https://{$matches[2]}");
} else {
preg_match("/^(http:\/\/)?([^\/]+)/i", $last_host, $matches);
header("Access-Control-Allow-Origin: http://{$matches[2]}");
}
}
public function corsGetFunc()
{
setcookie('name_get', 'yole_get', time() + 60 * 60);
$data = ['g' => 'get'];
echo \json_encode($data);
exit;
}
public function corsPostFunc()
{
setcookie('name_post', 'yole_post', time() + 60 * 60);
$data = ['p' => 'post'];
echo \json_encode($data);
exit;
}