location跳转和header跳转的区别

1:header("location:url") 跳转之前不能有任何输出,如果想在header之前有输出,则要修改php.ini文件。具体 output_handler =mb_output_handler 或 output_handler =on

2:header()跳转之后必须有exit;结束,否则将继续执行下面的程序。

  标准的使用方法:

  ob_start();

  if(something){

    ob_clean();

    header("location:url");

    exit;

  }else{

    .......

  }

  ob_flush();

3:如果在牵涉到页面按照页面头信息HTTP_REFERER来统计流量的时候,不能使用header()跳转,因为header()在跳转的过程中HTTP_REFERER在90%以上的主流浏览器会丢失。此时可以使用location.href来替换,来解决流量被统计到的问题!

posted @ 2014-01-10 17:21  飞一样的编码  阅读(951)  评论(0编辑  收藏  举报