Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect function don't redirect to base_url #1611

Closed
dasua opened this issue Dec 15, 2018 · 1 comment
Closed

redirect function don't redirect to base_url #1611

dasua opened this issue Dec 15, 2018 · 1 comment

Comments

@dasua
Copy link

dasua commented Dec 15, 2018

Describe the bug
This redirects fails in my controller when upgrading from V4.0.0-alpha2 to V4.0.0-alpha3 (or develop branch):

return redirect(base_url('/login'))->with('tplError', 'Invalid username or password');
return redirect('/login')->with('tplError', 'Invalid username or password');
return redirect(base_url('/dashboard/1'))->with('notifSuccess', 'Login OK');

The value of base_url('/login') is https://dev.dasua.es/login and this works when I write in the browser (is a valid url).

The value of base_url('/dashboard/1') is https://dev.dasua.es/dashboard/1 and this works when I write in the browser (is a valid url).

Throws CodeIgniter\HTTP\Exceptions\HTTPException BASEPATH/HTTP/Exceptions/HTTPException.php at line 106

At CodeIgniter\Router\RouteCollection::reverseRoute method, I get this values:
A partital content of $this->routes is:

reset($vars) array (10)
    * => array (0)
    options => array (0)
    get => array (6)
        / => array (1)
        login => array (1)
            route => array (1)
                login => string (32) "\App\Controllers\Auth::loginForm"
        logout => array (1)
        dashboard/([0-9]+) => array (1)
            route => array (1)
                dashboard/([0-9]+) => string (36) "\App\Controllers\Dashboard::index/$1"

The value of $search method parameter is https://dev.dasua.es/login.

The value of ...$params is an empty array.

CodeIgniter 4 version
v4.0.0-alpha.3 or develop branch

Affected module(s)
CodeIgniter\Router\RouteCollection::reverseRoute()

Expected behavior, and steps to reproduce if appropriate
I think (as describe the function doc):
return redirect(base_url('/login'))->with('tplError', 'Invalid username or password');
return redirect('/login')->with('tplError', 'Invalid username or password');

Must have the same behavior as:
return redirect('login')->with('tplError', 'Invalid username or password'); (this works)

And:
return redirect(base_url('/dashboard/1'))->with('notifSuccess', 'Login OK');
return redirect('/dashboard/1')->with('notifSuccess', 'Login OK');
return redirect('dashboard/1')->with('notifSuccess', 'Login OK');

Must have the same behavior as:

$this->session->setFlashdata('notifSuccess', 'Login OK');
return $this->response->redirect(base_url('/dashboard/1'));

Context

  • OS: Debian Stretch
  • Web server Apache 2.4
  • PHP version 7.2

debug
exception

@lonnieezell
Copy link
Member

When using redirect('foo') it treats that as a reverse-routed request, which is why 'login' works but base_url('login') doesn't. That is in the docs, and is there as a security helper.

If you need to specify a full url, use redirect()->to('foo') instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants