Using header() to Set Content Type in PHP


Specify the content type of the output with the header() function, useful for APIs or serving different types of content.

Source Code

header('Content-Type: application/json');
echo json_encode(['message' => 'Hello, World!']);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments