icewating 发表于 2012-1-2 15:25:14

header一个很奇怪的问题

   public function __construct(){
                parent::__construct();
                $this->load->library('session');
                $this->load->model('index_model');
                $this->load->model('init_model');
               
                if (!$this->init_model->is_login()){
                        //未登录时,跳转至登陆页面
                       
                        header("Location://www.example.com/pg/index.php/transit/index/");
                       
                        exit();
                }
               
        }




这个问题很奇怪,当不写exit()时header就无法发送,写了exit()后,header就可以发送,这是为什么啊


手心手背 发表于 2012-1-3 09:38:08

header发送前有输出?

huboo82 发表于 2012-1-3 22:12:49


<?php
header('Location: http://www.example.com/');
?>


PHP 里 header 的 Location 用法是这样的,你的 header 似乎写错了。

柏新星 发表于 2012-1-4 09:22:58


if (!function_exists('redirect')) {

    function redirect($uri = '', $method = 'location', $http_response_code = 302) {
      if (!preg_match('#^https?://#i', $uri)) {
            $uri = site_url($uri);
      }

      switch ($method) {
            case 'refresh' : header("Refresh:0;url=" . $uri);
                break;
            default : header("Location: " . $uri, TRUE, $http_response_code);
                break;
      }
      exit;
    }

}

uri 写成带http://的就直接跳转 否则 去配置文件获取项目路径再跳转
页: [1]
查看完整版本: header一个很奇怪的问题