PHPackages                             mangel1196/php-cors - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. mangel1196/php-cors

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mangel1196/php-cors
===================

Cross-origin resource sharing library for the Symfony HttpFoundation

00PHP

Since Jul 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mangel1196/php-cors)[ Packagist](https://packagist.org/packages/mangel1196/php-cors)[ RSS](/packages/mangel1196-php-cors/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

CORS for PHP (using the Symfony HttpFoundation)
===============================================

[](#cors-for-php-using-the-symfony-httpfoundation)

[![Unit Tests](https://github.com/fruitcake/php-cors/actions/workflows/run-tests.yml/badge.svg)](https://github.com/fruitcake/php-cors/actions)[![PHPStan Level 9](https://camo.githubusercontent.com/66ba0baab49056b29c513a4a7c6d672e08da7a5e456be4228ad8ca52a87a4385/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230392d626c7565)](https://github.com/fruitcake/php-cors/actions)[![Code Coverage](https://camo.githubusercontent.com/ce3be308ae17b5c72b6f5f6da39c1b2947df3ec630893608ce429eb2dd08928b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6465436f7665726167652d3130302532352d627269676874677265656e)](https://github.com/fruitcake/php-cors/actions/workflows/run-coverage.yml)[![Packagist License](https://camo.githubusercontent.com/b2786cf7e73bc95855ee9a80aae82c5efd69e525ec7487deb2d8186922c53d80/68747470733a2f2f706f7365722e707567782e6f72672f667275697463616b652f7068702d636f72732f6c6963656e73652e706e67)](http://choosealicense.com/licenses/mit/)[![Latest Stable Version](https://camo.githubusercontent.com/481c68ebc694e461bbea4d8960fc585bd089abd2bc9d6252830d2d074f2fbb9e/68747470733a2f2f706f7365722e707567782e6f72672f667275697463616b652f7068702d636f72732f76657273696f6e2e706e67)](https://packagist.org/packages/fruitcake/php-cors)[![Total Downloads](https://camo.githubusercontent.com/ef4e373353420e3e0ed960298df9e358a0bd620c25b6baa6be72ca0372241e5c/68747470733a2f2f706f7365722e707567782e6f72672f667275697463616b652f7068702d636f72732f642f746f74616c2e706e67)](https://packagist.org/packages/fruitcake/php-cors)[![Fruitcake](https://camo.githubusercontent.com/28d7584b52e33d7b4ffb6b1bef8b89b6e598adb45c8c0d5f80349c1c304f385e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f776572656425323042792d467275697463616b652d6232626333352e737667)](https://fruitcake.nl/)

Library and middleware enabling cross-origin resource sharing for your http-{foundation,kernel} using application. It attempts to implement the [W3C Recommendation](http://www.w3.org/TR/cors/) for cross-origin resource sharing.

> Note: This is a standalone fork of  and is compatible with the options for CorsService.

Installation
------------

[](#installation)

Require `fruitcake/php-cors` using composer.

Usage
-----

[](#usage)

This package can be used as a library. You can use it in your framework using:

- [Stack middleware](http://stackphp.com/):
- [Laravel](https://laravel.com):

### Options

[](#options)

OptionDescriptionDefault valueallowedMethodsMatches the request method.`[]`allowedOriginsMatches the request origin.`[]`allowedOriginsPatternsMatches the request origin with `preg_match`.`[]`allowedHeadersSets the Access-Control-Allow-Headers response header.`[]`exposedHeadersSets the Access-Control-Expose-Headers response header.`[]`maxAgeSets the Access-Control-Max-Age response header.`0`supportsCredentialsSets the Access-Control-Allow-Credentials header.`false`The *allowedMethods* and *allowedHeaders* options are case-insensitive.

You don't need to provide both *allowedOrigins* and *allowedOriginsPatterns*. If one of the strings passed matches, it is considered a valid origin. A wildcard in allowedOrigins will be converted to a pattern.

If `['*']` is provided to *allowedMethods*, *allowedOrigins* or *allowedHeaders* all methods / origins / headers are allowed.

> Note: Allowing a single static origin will improve cacheability.

### Example: using the library

[](#example-using-the-library)

```
