PHPackages                             medz/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. medz/cors

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

medz/cors
=========

PHP CORS (Cross-origin resource sharing) middleware.

v1.5.0(6y ago)27491.9k↓44%23[2 issues](https://github.com/medz/cors/issues)3MITPHPPHP &gt;=7.0

Since Mar 14Pushed 6y ago8 watchersCompare

[ Source](https://github.com/medz/cors)[ Packagist](https://packagist.org/packages/medz/cors)[ GitHub Sponsors](https://github.com/medz)[ RSS](/packages/medz-cors/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (17)Used By (3)

CORS
====

[](#cors)

[![PHP Composer](https://github.com/medz/cors/workflows/PHP%20Composer/badge.svg)](https://github.com/medz/cors/workflows/PHP%20Composer/badge.svg)[![StyleCI](https://camo.githubusercontent.com/bfdf93ac7e12bcd3f4a0945b78636bada719143a765f0b4133effa847ee0c3ab/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132353030313431332f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/125001413)[![Build Status](https://camo.githubusercontent.com/4a6c2c467c44c1097007510c8de2c7c539408e5ae196ac8e08cfc12231e7ccdd/68747470733a2f2f7472617669732d63692e6f72672f6d65647a2f636f72732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/medz/cors)[![FOSSA Status](https://camo.githubusercontent.com/03587f4ed7617dd3aa33b70cc83d7288bd18e99c391627b0b48a5c1de8d33531/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466d65647a253246636f72732e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmedz%2Fcors?ref=badge_shield)

PHP CORS (Cross-origin resource sharing) middleware.

Support
-------

[](#support)

- [Array, Coding in Native PHP](#array)
- [Using PSR-7](#psr-7)
- [PSR-15 Support](https://github.com/medz/cors/blob/master/docs/psr-15-support.md)
- Symfony Support
- [Laravel Support](https://github.com/medz/cors/blob/master/docs/using-by-laravel.md)
- [Lumen Support](https://github.com/medz/cors/blob/master/docs/using-by-lumen.md)
- Yii2 Support
- [Swoft Framework](https://github.com/medz/cors/blob/master/docs/using-by-swoft.md)
- [Slim Framework](https://github.com/medz/cors/blob/master/docs/using-by-slim.md)
- [ThinkPHP Support](https://github.com/medz/cors/blob/master/docs/using-by-thinkphp.md)

Using
-----

[](#using)

```
composer require medz/cors
```

Example:

```
use Medz\Cors\Cors;

$cors = new Cors($config); // The $config 👉 `config/cors.php` file.
$cors->setRequest($requestType, $request); // The $request is empty array or is `NULL` or $_REQUEST
$cors->setResponse($responseType, $response); // The $response is empty array.
$cors->handle();

$response = $cors->getResponse();
```

Both `$requestType` and `$responseType` are of any type that is individually set to support, but if used in a framework, these two values are usually the same. Because you can set it up individually, you can deliver different values depending on your needs to achieve your goals.

### Configure

[](#configure)

The config example:

```
$config = [
    'allow-credentials' => false, // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
    'allow-headers'      => ['*'], // ex: Content-Type, Accept, X-Requested-With
    'expose-headers'     => [],
    'origins'            => ['*'], // ex: http://localhost
    'methods'            => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
    'max-age'            => 0,
];
```

### Array

[](#array)

```
use Medz\Cors\Cors;

$cors = new Cors($config);
$cors->setRequest('array', $request);
$cors->setResponse('array', $response);
$cors->handle();

$responseHeadersArray = $cors->getResponse();
```

### PSR-7

[](#psr-7)

```
use Medz\Cors\Cors;

$cors = new Cors($config);
$cors->setRequest('psr-7', $request);
$cors->setResponse('psr-7', $response);

$response = $cors->getResponse();
```

### Other

[](#other)

Because of the interface features provided by this package, you can implement it in a small amount of code in any other framework.

### Excellent Repositories

[](#excellent-repositories)

- [ThinkSNS+](https://github.com/slimkit/thinksns-plus) A strong community system

License
-------

[](#license)

The component is open-sourced software licensed under the [MIT license](https://github.com/medz/cors/blob/master/LICENSE).

[![FOSSA Status](https://camo.githubusercontent.com/e16b2999653a55869d17504affbbcaa1b1d9b278424a96af500473ef9c740401/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466d65647a253246636f72732e7376673f747970653d6c61726765)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmedz%2Fcors?ref=badge_large)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 99.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Recently: every ~147 days

Total

16

Last Release

2224d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5564821?v=4)[Seven Du](/maintainers/medz)[@medz](https://github.com/medz)

---

Top Contributors

[![medz](https://avatars.githubusercontent.com/u/5564821?v=4)](https://github.com/medz "medz (128 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")

---

Tags

corscors-middlewarecors-requestcrossdomainlaravellaravel5middlewarephpphp-corspsr-15psr-7requestresponseslimswoftsymfonythinkphpyii2responserequestpsr-7phpmiddlewaresymfonylaravelcorsslimpsr-15crossdomainyii2laravel5php-corsthinkphpcors-request

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/medz-cors/health.svg)

```
[![Health](https://phpackages.com/badges/medz-cors/health.svg)](https://phpackages.com/packages/medz-cors)
```

###  Alternatives

[psr/http-server-middleware

Common interface for HTTP server-side middleware

18291.2M1.5k](/packages/psr-http-server-middleware)[tuupola/cors-middleware

PSR-7 and PSR-15 CORS middleware

1331.8M24](/packages/tuupola-cors-middleware)[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[idealo/php-middleware-stack

Implementation of HTTP Middleware PSR-15 specification

318.9k](/packages/idealo-php-middleware-stack)[middlewares/response-time

Middleware to save the response time into the X-Response-Time header

14278.7k4](/packages/middlewares-response-time)[northwoods/router

Fast router for PSR-15 request handlers

161.4k](/packages/northwoods-router)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
