79618571

Date: 2025-05-12 20:14:40
Score: 0.5
Natty:
Report link

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();
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Javad Mahmoodi