用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2226|回复: 3
收起左侧

[HELP] header一个很奇怪的问题

[复制链接]
发表于 2012-1-2 15:25:14 | 显示全部楼层 |阅读模式
PHP复制代码
     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/");
                       
                        [color=#ff0000]exit();
                }
               
        }
 
 
 
复制代码


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


发表于 2012-1-3 09:38:08 | 显示全部楼层
header发送前有输出?
发表于 2012-1-3 22:12:49 | 显示全部楼层
PHP复制代码
 
<?php
header('Location: [url]http://www.example.com/'[/url]);
?>
 
复制代码


PHP 里 header 的 Location 用法是这样的,你的 header 似乎写错了。
发表于 2012-1-4 09:22:58 | 显示全部楼层
PHP复制代码
 
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://的就直接跳转 否则 去配置文件获取项目路径再跳转

本版积分规则