PHP code example of cspray / labrador-http-cors
1. Go to this page and download the library: Download cspray/labrador-http-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/ */
cspray / labrador-http-cors example snippets
use Cspray\Labrador\Http\Cors\ConfigurationBuilder;
use Cspray\Labrador\Http\Cors\SimpleConfigurationLoader;
use Cspray\Labrador\Http\Cors\CorsMiddleware;
$configuration = ConfigurationBuilder::forOrigins('https://example.com', 'https://foo.example.com')
->allowMethods('GET', 'POST', 'PUT', 'DELETE')
->withMaxAge(8600)
->allowRequestHeaders('X-Request-Header')
->exposeResponseHeaders('X-Response-Header')
->doAllowCredentials()
->build();
$loader = new SimpleConfigurationLoader($configuration);
$middleware = new CorsMiddleware($loader);