PHPackages                             eko3alpha/slim-cors-middleware - 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. eko3alpha/slim-cors-middleware

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

eko3alpha/slim-cors-middleware
==============================

Slim 3 CORS Multi-Origin Middleware

1.1.3(9y ago)439.4k2[1 issues](https://github.com/eko3alpha/slim-cors-middleware/issues)MITPHPPHP &gt;=5.5.0

Since Apr 12Pushed 9y agoCompare

[ Source](https://github.com/eko3alpha/slim-cors-middleware)[ Packagist](https://packagist.org/packages/eko3alpha/slim-cors-middleware)[ Docs](https://github.com/eko3alpha/slim-cors-middleware)[ RSS](/packages/eko3alpha-slim-cors-middleware/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (3)Versions (7)Used By (0)

slim-cors-middleware ([Slim v3.x](https://github.com/slimphp/Slim/))
====================================================================

[](#slim-cors-middleware-slim-v3x)

[![Packagist](https://camo.githubusercontent.com/bcc77ada06d40965fc9d770a83d707273dd3b6eb782f3eb25475d3b1cb7650b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656b6f33616c7068612f736c696d2d636f72732d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eko3alpha/slim-cors-middleware)[![Packagist](https://camo.githubusercontent.com/7acdb120d4c766da0b2255b6a1900f77ad6268f9571b3e5998fa1cb3fc821ec2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656b6f33616c7068612f736c696d2d636f72732d6d6964646c65776172652e737667)](https://packagist.org/packages/eko3alpha/slim-cors-middleware)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6737bafc8311de53e201265ce7fc0ecf0d196a810ef72eacfd0e12f67c5c7c22/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656b6f33616c7068612f736c696d2d636f72732d6d6964646c65776172652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/eko3alpha/slim-cors-middleware/?branch=master)[![Build Status](https://camo.githubusercontent.com/4dbbd50db92a49713c4ad1ce633cd41f75b257c5fad99c5a0f2db63d6362e227/68747470733a2f2f7472617669732d63692e6f72672f656b6f33616c7068612f736c696d2d636f72732d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/eko3alpha/slim-cors-middleware)

A middleware to handle Cors for multiple domains using Slim. "Access-Contro-Allow-Origin" only accepts one domain or a wildcard. This makes it troublesome if you want to allow different domains access to your api. In order to allow access to multiple domains You either need to create an .htaccess/apache rule: [credit](https://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains)

```

        SetEnvIf Origin "^http(s)?:\/\/(www\.|dev\.|local\.)?(domain\.com|domain2\.com)$" AccessControlAllowOrigin=$0
        Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin

```

Or you have to use a wildcard. It's an all or very restrictive approach, which encourage most dev's to opt for the very easy wildcard '\*' approach.

```
Access-Control-Allow-Origin: *

```

This middleware will detect the origin of a request, if its within the allowed list it will set the proper "Access-Control-Allow-Origin" value for that domain, as well as restrict the methods it has access to.

```
Access-Control-Allow-Origin: https://client.domain.com

```

Install
-------

[](#install)

You can either download manually or use composer.

```
composer require eko3alpha/slim-cors-middleware

```

Usage
-----

[](#usage)

```
$app = new \Slim\App();

$app->add(new \Eko3alpha\Slim\Middleware\CorsMiddleware([
    'https://dev.domain1.com' => ['GET', 'POST'],
    'https://dev.domain2.com' => ['GET', 'POST'],
    'https://dev.domain3.com' => ['GET']
  ]);
```

Examples
--------

[](#examples)

This middleware allows you to add method restrictions on a per domain basis. Below are some examples of valid configuration options. HTTP and HTTPS are considered 2 different origins.

One entry with a wildcard, this will give GET access to all domains requesting resources

```
$app->add(new \Eko3alpha\Slim\Middleware\CorsMiddleware([
  '*' => 'GET'
]);
```

This will give GET, POST and DELETE access to both http and https versions of api.domain.com, you can either use a string value or array.

```
$app->add(new \Eko3alpha\Slim\Middleware\CorsMiddleware([
  'http://client.domain.com'  => 'GET, POST, DELETE',
  'https://client.domain.com' => ['GET', 'POST', 'DELETE']
]);
```

You can either choose to have your methods as an array \['GET', 'POST'\] or string 'GET, POST'.

Slim Container
--------------

[](#slim-container)

You can use Slim's container to hold the configuration if you prefer to have your configuration in a seperate file.

```
$container = new Slim\Container;

.
.
.

$container['cors'] = ['*' => 'GET, POST'];

.
.
.

$app->add(new \Eko3alpha\Slim\Middleware\CorsMiddleware($container['cors']);
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

6

Last Release

3365d ago

Major Versions

0.1.1 → 1.0.02017-04-12

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1705908?v=4)[Angel Alvarado](/maintainers/eko3alpha)[@eko3alpha](https://github.com/eko3alpha)

---

Top Contributors

[![eko3alpha](https://avatars.githubusercontent.com/u/1705908?v=4)](https://github.com/eko3alpha "eko3alpha (19 commits)")

---

Tags

psr-7middlewarecorsslim

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eko3alpha-slim-cors-middleware/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.8k](/packages/guzzlehttp-psr7)[mezzio/mezzio

PSR-15 Middleware Microframework

3913.8M120](/packages/mezzio-mezzio)[tuupola/cors-middleware

PSR-7 and PSR-15 CORS middleware

1331.9M29](/packages/tuupola-cors-middleware)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

577.0M95](/packages/laminas-laminas-stratigility)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28545.4k3](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

131.7M39](/packages/mezzio-mezzio-authentication)

PHPackages © 2026

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