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

route_to issue #198

Closed
bono95zg opened this issue Apr 17, 2020 · 4 comments
Closed

route_to issue #198

bono95zg opened this issue Apr 17, 2020 · 4 comments

Comments

@bono95zg
Copy link

When baseURL is like www.example.com/folder/public/
I get to many redirects. I inspected it and it turns out in LoginFilter.php route_to returns ('/login') but $current is equal to ('/folder/public/login') and it loops forever.

What would be the most elegant way to solve this? Keep in mind I need to be able to have multiple applications installed (www.example.com/project1/public/, www.example.com/project2/public/).

@lonnieezell
Copy link
Owner

Which version of CI4 are you using? I think most of this path issues like that should be fixed in 4.0+

@bono95zg
Copy link
Author

i use the latest ci4

@SoulReaver
Copy link

SoulReaver commented May 11, 2020

I had the same issue, but I am not 100% sure what caused it. I am also not using Myth/Auth directly - I am writing something in PHP for the first time in 10 years, so I am using it to learn CI more than simply for auth stuff.

Anyway, here's what I wrote:

$current = (string)uri_string();

// to match route_to's broken relativeness
if ( substr( $current, 0, 1 ) !== '/' )
	$current = '/' . $current;

if ( in_array( $current, [ route_to( 'login' ) ] ) ) { ...

A lot depends on how you would like to treat PATH part of url.

originally used method, that uses current_url() returns path part of URL seen from outside (what client sees). It can be fixed to omit parts common with base url.

uri_string() (that I used) returns path part of the URL according to docs, but actually it returns path relative to base_url (and I am very glad it does that, since otherwise it would give same result as method used originally), i.e. PATH as seen by CI developer.

finally route_to according to docs returns relative uri ('login'), while returned path IS NOT relative ('/login'). It might not look like an issue while you write server side code (since you "root" everything at base url), but when you start using that in templates, you're doomed, depending on what's the base_url of your service - is that just domain (you're safe thanks to the bug) or like in this case you have something in path part of the URI.

@lonnieezell
Copy link
Owner

I believe this was caused by an issue CI was having at the time that should have been fixed in 4.0.4. Closing.

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

3 participants