Download the PHP package phputil/cors without Composer
On this page you can find all versions of the php package phputil/cors. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package cors
phputil/cors
🔌 CORS middleware for phputil/router
- Unit-tested ✔
- Well-documented 📖
- Syntax compatible with expressjs/cors 🎯
Installation
Requires phputil/router v0.2.14+
Usage
Basic usage
API
$options
can be an array or an object from the class CorOptions
. All its keys/attributes are optional:
origin
- Configures the response header
Access-Control-Allow-Origin
, which indicates the allowed origin. - Allowed types:
bool
,string
,array
. true
, the default value, reflects theOrigin
request header - that is, it allows any origin.false
makes it to return'*'
as the header value.- A non-empty
string
value (e.g.'mydomain.com'
) restricts theOrigin
to the defined value. - A non-empty
array
value indicates thatOrigin
values are allowed. - When the
Origin
request header is not sent and the optionorigin
istrue
, it will return*
- aiming to accept any origin. Other options will block the request. - Using
*
may not work when using credentials or using httpS. Prefer sending the request headerOrigin
whenever possible.
credentials
- Configures the response header
Access-Control-Allow-Credentials
. - Allowed types:
bool
. true
, the default value, makes it to include the header.false
makes it to omit the header.- This header is important if your application uses cookies or some kind of authentication header.
methods
- Configures the response header
Access-Control-Allow-Methods
. - Allowed types:
string
,array
. - The default value is
GET,HEAD,OPTIONS,POST,PUT,DELETE,PATCH
. - HTTP methods in a
string
must be separated by comma.
allowedHeaders
- Configures the response header
Access-Control-Allow-Headers
. - Allowed types:
string
,array
. - The default value is
'*'
, meaning to accept any request header. - HTTP headers in a
string
must be separated by comma.
exposedHeaders
- Configures the response header
Access-Control-Expose-Headers
. - Allowed types:
string
,array
. - The default value is
''
(empty string), meaning to not include the header. - HTTP headers in a
string
must be separated by comma.
maxAge
- Configures the response header
Access-Control-Max-Age
. - Allowed types:
int
,null
. - The default value is
null
, meaning to not include the header. - An
int
value means the number of seconds that a preflight request can be cached (by the browser).
Example
Using an array:
Using the class CorOptions
, that has nestable builder methods with the prefix with
:
License
Thiago Delgado Pinto
All versions of cors with dependencies
PHP Build Version
Package Version
Requires
ext-mbstring Version
*
The package phputil/cors contains the following files
Loading the files please wait ....