I am creating an API, using PHP. I am getting the following errors:
Warning: Cannot modify header information - headers already sent by (output started at xxx/api/index.php:1) in xxx/api/index.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at xxx/api/index.php:1) in xxx/api/index.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at xxx/api/index.php:1) in xxx/api/index.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at xxx/api/index.php:1) in xxx/api/index.php on line 5
Warning: Cannot modify header information - headers already sent by (output started at xxx/api/index.php:1) in xxx/api/index.php on line 6
There is not white-space above or below, still I am getting the warnings! Below is my code:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
echo '{"abc":"abc"}';
?>
Any help will be appreciated!
PS: Why this is being marked as duplicate! I assume the problem is being caused by the headers! and all other questions are of different criteria!
Thanks