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 issue with checkAuthentication() #681

Closed
lkissorban opened this issue Jul 21, 2015 · 9 comments
Closed

redirect issue with checkAuthentication() #681

lkissorban opened this issue Jul 21, 2015 · 9 comments

Comments

@lkissorban
Copy link

The redirect is not working after login, as the url is duplicated.

Solution:
in config.php a new line after 'URL' definition:
'BASE_URL' => str_replace('public', '', dirname($_SERVER['SCRIPT_NAME'])),
in Auth.php change the header() line to:
header('location: ' . Config::get('URL') . 'login?redirect=' . urlencode(substr($_SERVER['REQUEST_URI'],strlen(Config::get('BASE_URL')))));

L

@panique
Copy link
Owner

panique commented Jul 21, 2015

Sorry I don't understand the problem to be honest. Can you go into detail what "the url is duplicated" means ? THanks!

@lkissorban
Copy link
Author

Test it...

  1. Login to the app, go to the dashboard, which accessable only when you are logged in. Copy the url...
  2. Log out.
  3. Paste the dashboard url and send it.
  4. You will be redirected to the login screen, with the dashboard url as requested screen.
  5. After log in again, the url will be this:
    http://localhost/projects/huge-master/projects/huge-master/dashboard/index
    and it"s resulted as a 404 error...

L

@Dominic28
Copy link
Contributor

That's a problem if you install the script in subfolders only.
A quick solution would be to manually filter out the subfolder from $_SERVER['REQUEST_URI'] in the Auth class. But I got no idea right now to solve this for everyone.

@lkissorban
Copy link
Author

It was a nice improvement to automatically follow the subdirectories by the config, so I tought it will be usefull, if the redirect process fits itself also. But anyway, it's a nice framework, and helps me a lot in my small projects.
Thx

@panique
Copy link
Owner

panique commented Jul 22, 2015

@lkissorban Okay, I see, but this problem only exists when you don't install the framework properly! Usually an application will not have something like "/projects/huge-master/projects/huge-master/" inside the URL.

But to be fair, you're right, this is definitly not optimal for people who want to install it inside a subfolder. Hmm, let's put this on the TODO-liste, maybe someone has a really good solution here!

Can I ask you: Are there any other problems beside this redirect when using huge in a subfolder (i mean, when the URL has the subfolder inside) ?

@lkissorban
Copy link
Author

No, it's working fine in a subfolder.

@mcanatalay
Copy link
Contributor

Here what have I done for this issue,

First as you suggest I added base_url to config,

'BASE_URL' => str_replace('public', '', dirname($_SERVER['SCRIPT_NAME'])),

I added two function to Redirect Class

    /**
     * To the defined page
     *
     * @param $path
     */
    public static function back($redirect){
        header("location: " . Config::get('URL') . ltrim(urldecode(Request::post('redirect')), '/'));
    }

    /**
     * Get current page which you wanted to redirect later
     *
     * @return $path
     */
    public static function get(){
        return urlencode(substr($_SERVER['REQUEST_URI'],strlen(Config::get('BASE_URL'))));
    }

How to use it? Well, first get() will give you url of current page which you will redirect after login or a post request. back() will take this get() value if you want and redirect you to that page.

Why have I done this? For simplicity. I don't like to use long length codes over and over again.

Here is my Auth class:

Redirect::to('login?redirect=' . Redirect::get());

Here is my code in LoginController class:

Redirect::back(Request::post('redirect'));

@panique
Copy link
Owner

panique commented Oct 11, 2015

Thanks, I'll link this issue from the readme troubleshooting section (and close this ticket), so people can find it easier.

@panique panique closed this as completed Oct 11, 2015
@ChaIcuWo
Copy link

+1 for this simple solution! Seems to have solved the issue for me entirely.

To expand slightly for others, in the LoginController class I replaced

$data = array('redirect' => Redirect::back(Request::post('redirect')) ? Redirect::back(Request::post('redirect')) : NULL);

with

$data = array('redirect' => Request::get('redirect') ? Request::get('redirect') : NULL);

and in the Auth class replaced

header('location: ' . Config::get('URL') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));

with

Redirect::to('login?redirect=' . Redirect::get());```

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

5 participants