blog

Home / DeveloperSection / Blogs / HTTP Functions in PHP

HTTP Functions in PHP

Anonymous User4550 04-Nov-2011

The HTTP functions let you manipulate information sent to the browser by the Web server, before any other output has been sent.

There are mainly four HTTP function which is used in PHP such as: header (), headerlist(), setcookie() and setrawcookie().

Let’s have a small demonstration about these functions, which elaborates how to use these function in PHP.

header () function:     

The header () function sends a raw HTTP header to a client.

Note: It is important to notice that header () must be called before any actual output is sent to the web browser.

Syntax:

header ($string, $replace, $http_response_code);

Here, $string is required parameter which specifies the header string to send, $replace is optional parameter which specifies the whether the header should replace previous or add a second header and last one is $http_response_code forces the HTTP response code to the specified value.

headerlist() function:

The headers_list() function returns a list of response headers sent to a client. This function returns an array of headers.

Syntax:

headers_list() ;

NB:  To determine whether or not the headers have been sent yet, use the headers_sent() function.

setcookie () function:     

The setcookie() function sends an HTTP cookie to a client.

Syntax:

setcookie (name, value, expire, path, domain, secure) ;

Here,       

Name -> It is the required parameter which specifies the name of cookie.

Value -> Value is required parameter which specifies the value of cookie.

Expire-> It is optional parameter which specifies when cookie expired.

Path-> Path is optional parameter which specifies the server path of the cookie.

Domain-> Domain is also optional parameter which specifies the domain name of cookie.

Secure-> Secure is optional parameter which specifies whether or not the cookie should only be transmitted over a secure HTTPS connection.

setrawcookie () function:

The setrawcookie () function sends an HTTP cookie without URL encoding the cookie value. This function returns ‘TRUE ‘on success or ‘FALSE’ on failure.

Syntax:

setrawcookie (name, value, expire, path, domain, secure) ;

Here,

Name -> It is the required parameter which specifies the name of cookie.

Value -> Value is required parameter which specifies the value of cookie.

Expire -> It is optional parameter which specifies when cookie expired.

Path -> Path is optional parameter which specifies the server path of the cookie.

Domain -> Domain is also optional parameter which specifies the domain name of cookie.

Secure -> Secure is optional parameter which specifies whether or not the cookie should only be     transmitted over a secure HTTPS connection. ‘TRUE’ indicates that the cookie will only be set if a secure connection exists. Default value is ‘FALSE’.

Thanks!!

Updated 18-Sep-2014
I am a content writter !

Leave Comment

Comments

Liked By