The use of this is to set the encoding, send HTTP status values, and redirect.
PHP Header UTF8:
Header ("content-type:text/html; Charset=utf-8″);
PHP header 404:
Header ("http/1.0 404 Not Found");
The above two examples are set UTF8 encoding
Sublime the menu bar->tools→new snippet→ Enter the following:[cdata[PHP//vim:set expandtab cindent tabstop=4 shiftwidth=4 fdm=marker://+------------------------------------------------ ----------------------+// | The CompanyName Inc |//+-------------
PHP header several uses, you know several?1. Jump pageHeader (' Location: '. $url); // There is no space between location and ': '. 2. Declaration Content-typeHeader (' Content-type:text/html;charset=utf-8 ');3. Return Response status CodeHeader ('
Implementing redirects in ASP is using the Response.Redirect function:
Use one example:
Response.Redirect ". /test.asp "
There are similar functions in PHP: Header
Use one example:
Header ("Location:.") /test.php ");
But there is a difference
This article mainly introduces the PHP header function common HTTP header settings, this article directly gives the code example, the code contains detailed comments, the need for friends can refer to the
?
1 2 3 4 5 6 7 8 9 10 11 12 13
The PHP settings cookie can use the Setcookie function or the header function. You need to pay attention to the order of the strings when using the header method, and unexpected problems may occur if the order is incorrect. The correct order is
This article introduces how to solve the php header 404 error file garbled. If you encounter such problems, refer.
Usually, when judging a non-existing resource (such as category or product does not exist) through php, you need to return a 404
The header () that needs attention here is most often taken to send the header (' Location:/'); And so on, do the Web redirect action.In use Setcookie (), header () ... You cannot use any output before such a function. Log records if necessary.If
If you have just started learning PHP, there may be many functions that need to be studied. Today we will learn how to use PHP Header (). For more instructions, please refer to the PHP Chinese manual. The following describes how to use the header
First look at the definition of official documents(PHP 4, PHP 5, PHP 7)header- Sending native HTTP headers1 Header string $string $replace true $http _response_code ]] )Parameters: StringThere are two kinds of special heads. The first type of "http/
200 normal stateHeader (' http/1.1 OK ');301 permanent Redirect, remember to add a redirect address at the back location: $urlHeader (' http/1.1 301 Moved permanently ');Redirect, in fact, is 302 temporary redirectHeader ('
PHP header send various types of files and settings file download name
Header (' content-type:application/image/pjpeg ');//type of outputHeader (' content-disposition:attachment; filename= ' downloaded.jpg '); Download the displayed name,
The header function of PHP can be used to implement META tags in HTML code with very little code.
here only to use the header function to do the page jump
1. Code for page jumps in HTML codeHTML Meta Refresh and jump (redirect) pageRefresh
1, location and ":" No space between, otherwise it will be wrong.
2, before using the header can not have any output.
3. The PHP code after the header will also be executed.
Here is a comparison with the redirect Response.Redirect in asp:
Example 1:
The usage and precautions of the header function in PHP are described in detail, and the phpheader function is described in detail. The usage and precautions of the header function in PHP are described in detail. voidheader (string $ string [, bool $
PHP header send various types of files and settings file download name
Header (' content-type:application/image/pjpeg ');//type of output
Header (' content-disposition:attachment; filename= ' downloaded.jpg '); Download the displayed name,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.