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

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

effectra/cors
=============

PHP library for enabling CORS (Cross-Origin Resource Sharing) in HTTP requests/responses. It follows PSR guidelines, and can be easily integrated into PHP projects.

v1.0.0(2y ago)124MITPHP

Since Jan 5Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Effectra/cors
=============

[](#effectracors)

Effectra/cors is a PHP package that provides middleware and service classes for handling Cross-Origin Resource Sharing (CORS) in web applications. CORS is a security feature implemented by web browsers to control access to resources on a different origin.

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

[](#installation)

You can install the Effectra/cors package via Composer:

```
composer require effectra/cors
```

Usage
-----

[](#usage)

### CorsMiddleware

[](#corsmiddleware)

The `CorsMiddleware` class is a PSR-15 middleware that can be used in a middleware stack to handle CORS requests. It checks incoming requests for CORS-related headers and adds appropriate headers to the response.

#### Example:

[](#example)

```
use Effectra\Cors\CorsMiddleware;
use Effectra\Cors\CorsService;
use Psr\Http\Server\MiddlewareInterface;

// Create a CorsService instance with desired configuration
$corsService = new CorsService([
    'allowedOrigins' => ['https://example.com'],
    'allowedMethods' => ['GET', 'POST'],
    'allowedHeaders' => ['Content-Type'],
]);

// Create the CorsMiddleware instance
$corsMiddleware = new CorsMiddleware($corsService, ['/api']);

// Add the middleware to your middleware stack
$middlewareStack = [
    // Other middleware...
    $corsMiddleware,
    // Other middleware...
];
```

### CorsService

[](#corsservice)

The `CorsService` class provides the core functionality for handling CORS requests. It allows you to configure various CORS-related settings.

#### Example:

[](#example-1)

```
use Effectra\Cors\CorsService;

// Create a CorsService instance with desired configuration
$corsService = new CorsService([
    'allowedOrigins' => ['https://example.com'],
    'allowedMethods' => ['GET', 'POST'],
    'allowedHeaders' => ['Content-Type'],
]);

// Check if a request is a CORS request
$isCorsRequest = $corsService->isCorsRequest($request);

// Check if a request is a preflight request
$isPreflightRequest = $corsService->isPreflightRequest($request);

// Handle a preflight request and add necessary headers to the response
$preflightResponse = $corsService->handlePreflightRequest($request);

// Check if a specific origin is allowed
$isOriginAllowed = $corsService->isOriginAllowed($request);

// Add CORS headers to the actual response
$actualResponse = $corsService->addActualRequestHeaders($response, $request);
```

Configuration
-------------

[](#configuration)

The `CorsService` class allows you to configure various CORS-related settings using an options array.

### Available Options:

[](#available-options)

- `allowedOrigins`: An array of allowed origins.
- `allowedOriginsPatterns`: An array of allowed origin patterns (wildcards).
- `allowedMethods`: An array of allowed HTTP methods.
- `allowedHeaders`: An array of allowed headers.
- `supportsCredentials`: Whether credentials (cookies, HTTP authentication) should be supported.
- `maxAge`: Maximum time (in seconds) that the results of a preflight request can be cached.
- `exposedHeaders`: An array of headers exposed to the response.

Contributing
------------

[](#contributing)

If you'd like to contribute to this project, please follow our [contribution guidelines](CONTRIBUTING.md).

License
-------

[](#license)

The Effectra/cors package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

864d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e6219ae87e98df8783b2f595b013035dd183c0712afd24045a8acf0a40c3bdf?d=identicon)[effectra](/maintainers/effectra)

---

Top Contributors

[![BMTmohammedtaha](https://avatars.githubusercontent.com/u/95439605?v=4)](https://github.com/BMTmohammedtaha "BMTmohammedtaha (2 commits)")

### Embed Badge

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

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

###  Alternatives

[relay/relay

A PSR-15 server request handler.

3302.1M86](/packages/relay-relay)[mezzio/mezzio-authentication-oauth2

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

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[openswoole/core

Openswoole core library

181.1M32](/packages/openswoole-core)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[jimtools/jwt-auth

PSR-15 JWT Authentication middleware, A replacement for tuupola/slim-jwt-auth

20142.3k3](/packages/jimtools-jwt-auth)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)

PHPackages © 2026

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