PHP code example of topthink / think-cors

1. Go to this page and download the library: Download topthink/think-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/ */

    

topthink / think-cors example snippets


[
    'paths' => ['api/*']
]

[
    'paths' => [
        'www.thinkphp.cn' => ['api/*'],
        'doc.thinkphp.cn' => ['user/*', 'article/*'],
    ]
]

[
    'allowed_origins' => ['*'],
]

[
    'allowed_origins' => ['www.thinkphp.cn', 'm.thinkphp.cn'],
]

[
    'allowed_origins_patterns' => ['#.*\.thinkphp\.cn#'],
]

[
    'allowed_methods' => ['*'],
]

[
    'allowed_methods' => ['GET', 'POST'],
]

[
    'allowed_headers' => ['*'],
]

[
    'allowed_headers' => ['X-Custom-Header', 'Upgrade-Insecure-Requests'],
]

[
    'max_age' => 7200,
]

[
    'supports_credentials' => true,
]

[
    'paths' => ['api/*'],
    ...
]