totorajo

enable cors

Dec 28th, 2022
1,939
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. // Allow from any origin
  2. if (isset($_SERVER['HTTP_ORIGIN'])) {
  3.     // should do a check here to match $_SERVER['HTTP_ORIGIN'] to a
  4.     // whitelist of safe domains
  5.     header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  6.     header('Access-Control-Allow-Credentials: true');
  7.     header('Access-Control-Max-Age: 86400');    // cache for 1 day
  8. }
  9. // Access-Control headers are received during OPTIONS requests
  10. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  11.  
  12.     if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
  13.         header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");        
  14.  
  15.     if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
  16.         header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  17.  
  18. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment