1. Go to this page and download the library: Download drewlabs/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/ */
drewlabs / cors example snippets
use Drewlabs\Cors\Cors;
$cors = new Cors();
use Drewlabs\Cors\Cors;
$cors = new Cors([ 'allowed_hosts' => 'http://localhost:3000', 'allowed_headers' => ['*'], 'allowed_methods' => ['*'] ]);
use Drewlabs\Cors\Cors;
use Drewlabs\Cors\ConfigurationBuilder;
$cors = new Cors(
ConfigurationBuilder::new()
// Add `Origin: http://localhost` header
->withHosts('http://localhost', 'http://localhost:3000')
// Add an `allowed_credentials: yes` header
->withCredentials()
->withMaxAge(0)
// Add an `Access-Control-Allow-Methods: POST` header configuration value
->withMethods('POST')
// Convert the builded configuration to array
->toArray()
);
use Drewlabs\Cors\Cors;
$cors = new Cors();
$cors->handleRequest(new Request());
use Drewlabs\Cors\Cors;
use Drewlabs\Cors\ConfigurationBuilder;
$cors = new Cors(
ConfigurationBuilder::new()
// Add `Origin: http://localhost` header
->withHosts('*')
// Convert the builded configuration to array
->toArray()
);
// Checks if the Psr request is a cors request
$cors->isCorsRequest(new Request());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.