The Header PHP Is Not Redirecting

The Header PHP Is Not Redirecting thumbnail
PHP generates HTML code.

All Web pages are written in Hypertext Markup Language (HTML). However, HTML does not have any programming capabilities and only formats data. PHP is one of the programming languages that Web developers use to generate Web pages. This introduces a programming element into websites. Redirection is one of the functions of a Web server and PHP code can invoke it. However, the same function for redirection can perform many other notifications, according to its settings.

  1. Redirection

    • If a Web page changes its file name, if that file is moved to another location on the same site, or if that page is moved to another site, any visitor to the page at the old address will be told that the file cannot be found. Redirection is implemented by a message from a Web server to a Web browser. The server tells the browser that the page has moved and gives the new address. The browser then reapplies to the new address for the page.

    HTTP Codes

    • The regular method for a redirect is to use functionality built into the Hypertext Transfer Protocol. HTTP dictates the format of messages between Web browsers and Web servers. HTTP includes a list of status codes including two codes for redirection. These are 301 for a permanent redirect and 302, officially labelled “Found,” for a temporary redirect, also called “redirection for unspecified reason.” The benefit to website administrators of the HTTP system is that the page can be removed from its old location.

    PHP Method

    • PHP includes a function that emulates HTTP codes. This is called “header.” The name derives from the fact that instructions in an HTTP message are called “HTTP Headers.” The header function has two modes of operation. The first registers which HTTP code will be sent in the message. The second assembles the HTTP header line incorporating an address given as a parameter. The address is the new address for the page. The HTTP Header generated by the command will carry the status code set up in the first invocation of the function. If no code has been set up, the function defaults to the 302 code, which is for a temporary redirect. However, HTTP codes cover a range of conditions and if the header function has been set up with a status code that does not relate to redirection, the function will not redirect. Also, thought the PHP method invokes redirect codes, it requires that the a file remains in the old location.

    PHP Redirection

    • If a Web page is held on a server as HTML, the file containing it will have the file extension “html” or “htm.” If the page is generated from a PHP program, the file containing the page will have the “php” file extension. If the Web designer wants to implement a redirect from the target file, the procedures for the redirect have to use an HTML function if the original file was HTML, or a PHP function if the original file was a PHP program. If the PHP file has an “htm” file extension, the PHP header function will not run.

Related Searches:

References

  • Photo Credit Comstock/Comstock/Getty Images

Comments

Related Ads

Featured