my api php code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$allowed_origins = [
"https://fbc.mysite.ir",
"https://mysite.ir",
"http://localhost:54992",
"http://localhost:55687",
"http://localhost:5173",
"http://127.0.0.1:5173",
];
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
if (in_array($origin, $allowed_origins)) {
header("Access-Control-Allow-Origin: $origin");
header("Access-Control-Allow-Credentials: true");
}
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}