Skip to content

Instantly share code, notes, and snippets.

@kongondo
Forked from avtaniket/cors.php
Created January 21, 2025 04:45
Show Gist options
  • Select an option

  • Save kongondo/bd241d628d6f890a30a022f5b9c5458e to your computer and use it in GitHub Desktop.

Select an option

Save kongondo/bd241d628d6f890a30a022f5b9c5458e to your computer and use it in GitHub Desktop.

Revisions

  1. @avtaniket avtaniket revised this gist Oct 27, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions cors.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    /* Handle CORS */

    // Specify domains from which requests are allowed
  2. @avtaniket avtaniket created this gist Oct 27, 2015.
    18 changes: 18 additions & 0 deletions cors.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    /* Handle CORS */

    // Specify domains from which requests are allowed
    header('Access-Control-Allow-Origin: *');

    // Specify which request methods are allowed
    header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');

    // Additional headers which may be sent along with the CORS request
    header('Access-Control-Allow-Headers: X-Requested-With,Authorization,Content-Type');

    // Set the age to 1 day to improve speed/caching.
    header('Access-Control-Max-Age: 86400');

    // Exit early so the page isn't fully loaded for options requests
    if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
    exit();
    }