PHP Function: Built-in Functions part 6

Today in Buit-in Funtions we will look at some HTTP functions.

header() 
The header() function outputs an HTTP header string, such as a location redirection. This output must occur before any other data is sent to the browser, including HTML tags. For example to use the header() function to redirect a user to a new location, use this code:

header(“Location: http://www.techsoftcenter.com”);
exit;
(TIP – Follow a header() statement with the exit command. This ensures that the code does not continue to execute.)

setcookie() 
The setcookie() function sends a cookie to the user. Cookies must be sent before any other header info is sent to the web browser. The syntax for setcookie() is

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

For example, you would use the following code to send a cookie called username with a value of joe that is valid for one hour within all directories on the pinehead.com domain:

setcookie(“username”,”joe”, time()+3600, “/”, “.techsoftcenter.com”);

Next php function: Built-in Functions part 7