Welcome Guest, Not a member yet? Register   Sign In
Redirect to another URL
#1

[eluser]jigen7[/eluser]
hi i got a this part of a code to my index in my user controller that redirects it to the login function but i want to do is redirect it to another url not within the site for example http://google.com and i cant find the way to do it can anyone help me through here thanks

Code:
function index()
    {
          redirect('user/login');
    }

#2

[eluser]Randy Casburn[/eluser]
Hi jigen7,

The CI redirect function will only work for 'local' uri segments (as you found out) ;-)

So you have two choices:

1) use raw PHP
Code:
header("Location: http://google.com, TRUE, 302");

or 2) use the CI Output Class

Code:
$this->output->set_header("Location: http://google.com, TRUE, 302");
Hope this helps,

Randy
#3

[eluser]jigen7[/eluser]
wahh yeah i totally forgot about raw php codes tsk tsk thanks thanks
#4

[eluser]Jamie Rumbelow[/eluser]
But be careful when using raw php - you can't send headers AFTER they've already been sent, so it's usually the best idea to use CI's output class.
#5

[eluser]Sarre[/eluser]
If this is the index from the User controller, and you have to redirect to another function in that same controller, you can just do
Code:
function index()
{
  $this->login();
}




Theme © iAndrew 2016 - Forum software by © MyBB