0

我的重定向不起作用,我看不出它不起作用的原因,任何人都可以看到原因,

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 消息。

有任何想法吗?

4

2 回答 2

4

如果您想“回家”到您在路线文件中建立的基地,只需输入:

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

如果您想实际使用您的代码去某个地方,只需传递 URI 段:

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

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

于 2010-02-15T16:19:28.543 回答
2

尝试用 uri_string() 替换 base_url()。从用户指南

不会指定完整的站点 URL,而只是指定要定向到的控制器的 URI 段。

于 2010-02-15T13:07:53.940 回答