html问题,浏览器怎么设置header

2025-03-12 09:11:06
推荐回答(2个)
回答1:

html问题,浏览器怎么设置header,简单点说,将是想用浏览器(客户端)发一个数据 。
header() 函数向客户端发送原始的 http 报头。认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数。
方法/步骤

1、定义和用法
  header() 函数向客户端发送原始的 http 报头。
  认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 php教程 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
  
  实例一
  代码如下复制代码
    // connect to the database:
  $dbc = @mysql教程i_connect ('localhost', 'username', 'password', 'test') or die ('

could not connect to the database!

');
  // get the latest dates as timestamps教程:
  $q = 'select unix_timestamp(max(date_added)), unix_timestamp(max(date_completed)) from tasks';
  $r = mysqli_query($dbc, $q);
  list($max_a, $max_c) = mysqli_fetch_array($r, mysqli_num);
  // determine the greater timestamp:
  $max = ($max_a > $max_c) ? $max_a : $max_c;
  // create a cache interval in seconds:
  $interval = 60 * 60 * 6; // 6 hours
  // send the header:
  header ("last-modified: " . gmdate ('r', $max));
  header ("expires: " . gmdate ("r", ($max + $interval)));
  header ("cache-control: max-age=$interval");
  ?>
  实例二
  代码如下复制代码
    // 结果出错
  // 在调用 header() 之前已存在输出
  header('location: http://www./');
  ?>语法
  header(string,replace,http_response_code)
  提示用户保存一个生成的 pdf 文件(content-disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框):
  代码如下复制代码
    header("content-type:application/pdf");
  // 文件将被称为 downloaded.pdf
  header("content-disposition:attachment;filename='downloaded.pdf'");
  // pdf 源在 original.pdf 中
  readfile("original.pdf");
  ?>
  
  

回答2:

header("Content-type: text/html; charset=utf-8");

把这句话放在之间就好了。还有不懂就追问