views:

356

answers:

2

My redirect is not working, I can see no reason why it is not working thouhg, can anyone see a reason,

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)));
        }
    }
}

if I replace the redirect with die() however I get the die messege.

Any ideas?

+1  A: 

Try replacing base_url() with uri_string(). From the User Guide:

You will not specify the full site URL, but rather simply the URI segments to the controller you want to direct to.

Ch4m3l3on
A: 

If you are wanting to go 'home' to the base you establish in your route file just put:

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

If you want to actually go somewhere with your code only pass the URI segments:

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

GL, and let me know if that doesn't work.

angryCodeMonkey