Code has been added to clipboard!

Understand PHP HTTP Response: Functions and Constants

Reading time 2 min
Published Aug 8, 2017
Updated Oct 2, 2019

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 http_response_code() function.

Now, there are various ways to control these responses. Let's see them in a table below:

Function Description
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.
Tutorial
Introduction
Installation
Syntax
Variable
Superglobals
Data Types
String
Array
Multidimensional Array
Sort Array
Constant
Operators
Cookies
Sessions
DateTime
Error Handling
Exception Handling
File
Write and Create File
File Open, Read and Close
File Upload
Filtering
Redirecting
Advanced Filters
Forms
Form Required Field
Validate Email/URL
Form Validation
Form Action
Function
Prepared Statements
JSON
Calendar
ZIP File
FTP
HTTP Response
DateTime Functions
Error Functions
File Function
Filter
Math Functions
Mail Function
Miscellaneous Functions
Date Format
String Functions
Array Functions
Directory Functions
MySQL Database
MySQL Connection
MySQL Create Database
MySQL Create Table
MySQL Delete Data
MySQL Insert Data
MySQL Get Last Record ID
MySQL Insert Multiple Records
MySQL Select Data
MySQL Limit Data
MySQL Update Data
MySQLi Functions
AJAX and MySQL
AJAX Search
AJAX Poll
RSS Reader
Read XML File in PHP
XML Parser
SimpleXML Parser
SimpleXML: Node and Attribute
Expat XML Parser
DOMDocument
Libxml Functions
SimpleXML Functions
XML Parsing Functions
PHP isset
PHP echo and print
PHP if else and elseif
PHP switch case
PHP include File
PHP while Loop
PHP for and foreach
PHP mail()
PHP explode()
PHP substr()
PHP str_replace()
PHP array_push
PHP count()