1. Go to this page and download the library: Download lm-commons/lmc-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/ */
lm-commons / lmc-cors example snippets
return [
'lmc_cors' => [
'allowed_origins' => ['*'],
'allowed_methods' => ['GET', 'POST', 'DELETE'],
],
'router' => [
'routes' => [
'readOnlyRoute' => [
'type' => 'literal',
'options' => [
'route' => '/foo/bar',
'defaults' => [
// This will replace allowed_methods configuration to only allow GET requests
// and only allow a specific origin instead of the wildcard origin
LmcCors\Options\CorsOptions::ROUTE_PARAM => [
'allowed_origins' => ['http://example.org'],
'allowed_methods' => ['GET'],
],
],
],
],
'someAjaxCalls' => [
'type' => 'literal',
'options' => [
'route' => '/ajax',
'defaults' => [
// This overrides the wildcard origin
LmcCors\Options\CorsOptions::ROUTE_PARAM => [
'allowed_origins' => ['http://example.org'],
],
],
],
'may_terminate' => false,
'child_routes' => [
'blog' => [
'type' => 'literal',
'options' => [
'route' => '/blogpost',
'defaults' => [
// This would only allow `http://example.org` to GET this route
\LmcCors\Options\CorsOptions::ROUTE_PARAM => [
'allowed_methods' => ['GET'],
],
],
],
'may_terminate' => true,
'child_routes' => [
'delete' => [
'type' => 'segment',
'options' => [
'route' => ':id',
// This would only allow origin `http://example.org` to apply DELETE on this route
'defaults' => [
\LmcCors\Options\CorsOptions::ROUTE_PARAM => [
'allowed_methods' => ['DELETE'],
],
],
],
],
],
],
],
],
],
],
];
use Laminas\Uri\UriFactory;
UriFactory::registerScheme('chrome-extension', 'Laminas\Uri\Uri');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.