HTTP Headers
- Access Control Allow Origin
-
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: http://example.com
Specifies a
- Content Type
-
Content-Type: text/html; charset=utf-8
Content-Type: application/json; charset=utf-8
Content-Type: multipart/form-data; boundary=something
Specifies a
- Access Control Allow Methods
-
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Methods: *
Specifies a
- Access Control Max Age
-
Access-Control-Max-Age: 3600
Specifies a
- Access Control Allow Headers
-
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Headers: *
Specifies a
PHP Usage
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
?>
Example
<?php
setcookie("TestCookie","SomeValue");
header("X-Sample-Test: foo");
header("Content-type: text/plain");
?>
<html>
<body>
<?php
var_dump(headers_list());
?>
</body>
</html>
array(3) {
[0]=>
string(32) "Set-Cookie: TestCookie=SomeValue"
[1]=>
string(18) "X-Sample-Test: foo"
[2]=>
string(38) "Content-type: text/plain;charset=UTF-8"
}