Several uses of PHP header

1. Go page

header ( 'the Location:'. $ URL);   // the Location and ":" no space between.

2. Statement content-type

header('content-type:text/html;charset=utf-8');

3. Return response status code

header('HTTP/1.1 404 Not Found');

4. Perform a jump after a certain time

header ( 'the Refresh: 10; URL = HTTP: //www.baidu.com/');   // 10s after the jump.

5. Control the browser cache

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");

6. Perform http verification

header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');

7. By downloading

header ( 'Content-the Type: file application / OCTET-Stream'); // set the content type
 header ( 'Content-Disposition: Attachment; filename = "in EXAMPLE.ZIP"'); // Set the user as an accessory MIME header ( 'Content Encoding--Transfer: binary '); // set the transmission header (' the content-the length: '. in EXAMPLE.ZIP' filesize ( ')); // set the content length

 

Original: https://www.cnblogs.com/liangdong/p/10405535.html

1. Go page

header ( 'the Location:'. $ URL);   // the Location and ":" no space between.

2. Statement content-type

header('content-type:text/html;charset=utf-8');

3. Return response status code

header('HTTP/1.1 404 Not Found');

4. Perform a jump after a certain time

header ( 'the Refresh: 10; URL = HTTP: //www.baidu.com/');   // 10s after the jump.

5. Control the browser cache

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");

6. Perform http verification

header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');

7. By downloading

header ( 'Content-the Type: file application / OCTET-Stream'); // set the content type
 header ( 'Content-Disposition: Attachment; filename = "in EXAMPLE.ZIP"'); // Set the user as an accessory MIME header ( 'Content Encoding--Transfer: binary '); // set the transmission header (' the content-the length: '. in EXAMPLE.ZIP' filesize ( ')); // set the content length

 

Guess you like

Origin www.cnblogs.com/showcase/p/12100397.html