codeigniter重定向

时间:2010-02-15 12:27:20

标签: php codeigniter codeigniter-url

我的重定向不起作用,我看不出它为什么不能正常工作,任何人都可以看到原因,

function createCookie() {
            $this->load->helper('url')
    // Function gets called when the user clicks yes on the firstTime menu.
    // The purpose of this function is to create a cookie for the user.
    // First we'll give them a unique ID
    // Set an expiration time
    $prefix = "bang";
    $unique = uniqid($prefix);
    $expireAt = time() + (60*60*24*30);
    // With the unique ID now available we can set our cookie doing the same function as before
    $_COOKIE[] = setcookie("bangUser", $unique, $expireAt, "/");
    // Now that the cookie is set we can do a 100% check, check that cookie is set and if it is redirect to
    // to the homepage
    if(isset($_COOKIE['bangUser'])) {

        // We need to save the cookie data to the database
        // First let's load the model for the cookies
        $this->load->model('cookieModel');
        if($this->cookieModel->saveCookieRecord($_COOKIE['bangUser'], $expireAt)) {
            redirect(base_url(), 'location');
        } else {
            die(var_dump($this->cookieModel->saveCookieRecord($_COOKIE['bangUser'], $expireAt)));
        }
    }
}

如果我用die()替换重定向,但是我得到了die messege。

有什么想法吗?

2 个答案:

答案 0 :(得分:4)

如果你想要在你的路线文件中建立基地“回家”,那就放:

redirect('', 'location'); // Passing no URI parameters so it goes to base route

如果你想真正去你的代码,只传递URI段:

redirect('users/logout/', 'location');

GL,如果不起作用,请告诉我。

答案 1 :(得分:2)

尝试用uri_string()替换base_url()。来自User Guide

  

您将指定完整的网站网址,而只是指向您要指向的控制器的URI细分。