header用法

<?php
header('HTTP/1.0 403 Forbidden');
?>
编码:
<?php
header('Content-Type: text/html; charset=utf-8');  //使用utf-8编码
?>
跳转:
<?php
//header('Location: index.php');  //url最好用绝对路径
header('Location: [url]http://www.baidu.com/[/url]'); 
exit(); //不要省略,否则程序会把本页解释完后才跳转。
?>
<?php
$host  = $_SERVER['HTTP_HOST'];
$uri  = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
//$extra = 'admin/index.php';
$extra = 'rss.php';
header("Location: [url]http://$host$uri/$extra[/url]");
exit;
?>
<?php
header('Refresh: 2; url=index.html');
echo '登录成功!'; 
?>

文件下载:
<?php
$filename = "theDownloadedFileIsCalledThis.mp3";
$myFile = "/absolute/path/to/my/file.mp3";  //可以从数据库读取
$mm_type="application/octet-stream";      //可以用程序判断后缀名
header("Cache-Control: public, must-revalidate");
header("Pragma: hack"); // WTF? oh well, it works...
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($myFile)) );
header('Content-Disposition: attachment; filename="'.$filename.'"'); //供下载时显示用的,可不是真实值
header("Content-Transfer-Encoding: binary\n");
readfile($myFile);
?>

禁用缓存:
<?PHP
// HTTP/1.0 and HTTP/1.1
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-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值