Today in Buit-in Funtions we will look at some HTTP functions.
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:
(TIP – Follow a header() statement with the exit command. This ensures that the code does not continue to execute.)
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”);