Web Development Course:
HTTP stands for Hypertext Transfer Protocol. It is called a protocol of request-response type. That means it functions by the server answering various requests it receives from the client (in this case, the Internet browser).
In this tutorial, we will explain in more detail what a PHP HTTP response is, how to set and modify it. Such a response can be modified in numerous ways, but to do that, a developer must have some knowledge on special functions.
PHP HTTP Response: Main Tips
- HTTP PHP functions allow you to manipulate PHP HTTP response (the information sent by your browser to server) before outputting it.
- These functions are inbuilt into PHP core.
List of Functions to Manipulate Responses
As we have already covered, exchanging data on the Internet consists of one side (client) asking for specific data and the other (server) supplying the requested information. A piece of data that server issues as an answer to a particular request is called a PHP HTTP response.
Response has the same structure as request. It consists of a status line, header and body. To set a certain PHP HTTP response, you should use
Now, there are various ways to control these responses. Let's see them in a table below:
|header()||Send raw HTTP header to client|
|headers_list()||Return list of PHP HTTP response headers already sent (or headers that are ready to be sent)|
|headers_sent()||Check if / where HTTP headers have been sent|
|setcookie()||Set cookie to send along with remaining HTTP headers|
|setrawcookie()||Set cookie (without URL encoding) to send along with remaining HTTP headers|
PHP HTTP Response: Summary
- When a client sends a request for certain information to the server, it provides it by sending a PHP HTTP response.
- Before HTTP data that your browser sends to the server is outputted, you can modify it using HTTP PHP functions.
- There's no need to install these functions separately.
How to Easily Make HTML Redirect to Another Page
Find out how to make HTML redirect to another page with a beginner-friendly tutorial. See examples of HTML redirects and learn to write your own.