PHP code example of rrd108 / cakephp-cors

1. Go to this page and download the library: Download rrd108/cakephp-cors library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rrd108 / cakephp-cors example snippets


'Cors' => [
  'AllowOrigin' => ['http://localhost:5173', 'https://example.com'],
]

'Cors' => [
    // Accept all origins
    'AllowOrigin' => true,
    // OR
    'AllowOrigin' => '*',

    // Accept one origin
    'AllowOrigin' => 'http://webmania.cc'

    // Accept many origins
    'AllowOrigin' => ['http://webmania.cc', 'https://example.com']
]

'Cors' => [
    'AllowCredentials' => true,
    // OR
    'AllowCredentials' => false,
]

'Cors' => [
    // shoud be an array
    'AllowMethods' => ['GET', 'POST'],
]

'Cors' => [
    // accept all headers
    'AllowHeaders' => true,

    // accept just authorization
    'AllowHeaders' => 'authorization',

    // accept many headers
    'AllowHeaders' => ['authorization', 'other-header'],
]

'Cors' => [
    // nothing
    'ExposeHeaders' => false,

    // string
    'ExposeHeaders' => 'X-My-Custom-Header',

    // array
    'ExposeHeaders' => ['X-My-Custom-Header', 'X-Another-Custom-Header'],
]

'Cors' => [
    // no cache
    'MaxAge' => false,

    // 1 hour
    'MaxAge' => 3600,

    // 1 day
    'MaxAge' => 86400,
]