<?php
require_once('session.php');
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    header("HTTP/1.1 403 Forbidden");
    echo "Access forbidden. Use HTTPS.";
    exit();
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
	if (isset($_POST['csrf_token']) && hash_equals($_POST['csrf_token'], $_SESSION['csrf_token'])){

       if($u['cuid'] == 1){ 
        $endpoint = $_POST['endpoint'];
        $token = $_POST['token'];
        $owner = $_POST['owner'];
        $query = mysqli_query($conn,"UPDATE `tb_apigames` SET `endpoint` = '$endpoint', `token` = '$token', `owner` = '$owner' WHERE cuid = 1") or die(mysqli_error());
        header('location:../api-games/?notif=1');
    } else {
        echo 'BOKEP CXFTEAMS';
    }
} else {
    // Regenerate CSRF token on each form request
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));

    // CSRF token is invalid, handle the error
    echo "Ngapain Bang Ngetamper Data Kah?";
    exit();
}
}

?>