HTTP Functions

These functions assist you in dealing with the HTTP protocol. The encoding and decoding functions are not normally needed, as PHP takes care of these actions automatically. But there are cases where the actions need to be done manually, so these functions are provided. The header and cookie functions are useful for either sending custom HTTP headers or sending cookies.

Here are the HTTP functions in PHP:

int header(string str)

Send a raw HTTP header

int headers_sent(void)

Return true if headers have already been sent, false otherwise

array parse_url(string url)

Parse a URL and return its components in an array

string rawurldecode(string str)

Decode a URL-encoded string

string rawurlencode(string str)

URL-encode a string

void setcookie(string name [, string value [, int expire [, string path [, string domain [, int secure ]]]]])

Send a cookie

string urldecode(string str)

Decode a URL-encoded string

string urlencode(string str)

URL-encode a string

Apache-Specific Functions

The following HTTP functions are only available if PHP is running as an Apache module:

class apache_lookup_uri(string URI)

Perform a partial request of the given URI to obtain information about it

string apache_note(string note_name [, string note_value])

Get and set Apache request notes

array getallheaders(void)

Fetch all HTTP request headers

int virtual(string filename)

Perform an Apache subrequest

Get PHP Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.