Advertisement
MertcanGokgoz

enable cors php

Dec 20th, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: mertcan
  5.  * Date: 28.11.2015
  6.  * Time: 22:38
  7.  */
  8.  
  9. // allowed origins
  10. $allowedOrigins = array(
  11.     '(http(s)://)?(www\.)?my\-domain\.com',
  12.     '(http(s)://)?(www\.)?my\-domain\.com',
  13.     '(http(s)://)?(www\.)?my\-domain\.com'
  14. );
  15.  
  16. if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') {
  17.     foreach ($allowedOrigins as $allowedOrigin) {
  18.         if (preg_match('#' . $allowedOrigin . '#', $_SERVER['HTTP_ORIGIN'])) {
  19.             header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
  20.             header('Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE');
  21.             header('Access-Control-Max-Age: 1728000');
  22.             header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
  23.             break;
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement