Download & Extend

Redirect to previous page on login

Project:CAS
Version:6.x-2.1
Component:CAS
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:login, redirect

Issue Summary

Is it possible to redirect to the page that the user was on when he pressed the login button? I tried putting this: "

<?php
print $_GET['q'];
?>
" in the "Initial login landing page" box, but it doesn't work. Thanks.

Comments

#1

veplus: Yes, there is some code in place to try to redirect to the previous page after login. Are you really using the 6.x-1.0 version?

#2

so it's supposed to work automatically? when i go to build/modules it says "6.x-1.0" for version. i wonder why it's not working? i have "Force redirection on initial login" unchecked. also tried it checked with leaving "Initial login landing page:" blank.

#3

veeplus: There's a 6.x-2.1 version. Try that one.

#4

i upgraded but it still doesn't redirect to the previous page.. is there some special setting that needs to be activated? i'm not seeing anything.

#5

(1): How are you triggering the CAS login? Are you clicking on a link? Using the altered login form (i.e., clicking on a button)?
(2): If you are not being redirected to the previous page, where are you being redirect to?

It'd be helpful to know the specifics of the actions you are taking, what you observe, and what the expected behavior would be.

For me, I have a menu item called "login" which points at '/cas'. The user clicks on that, is redirected to the campus CAS login page, and then is redirected back to the page they originally started on.

#6

in the CAS settings, i have it set so that CAS login is required for the page "login". then i have a link at the top of each page leading to this login page. now that i think about it, that doesn't seem like the right way to do it..

but what happens is the user clicks the link, gets redirected to our campus login page, and then is sent back to the homepage of the site (regardless of which page they were on when they clicked the login link).

how did you set up the /cas page? i tried adding a link to it, but when i use that to log in, i still get redirected to the home page. "force redirection on initial login" is not checked.

thanks for the help!

#7

There should have been a menu item created called "Login" which points to /cas. It has some auto-detection setup so it only displays if a user is not currently logged in.

Otherwise creating a link to 'cas' should be enough. Odd that you are still be redirected to the page...

#8

There were some bugs that have been fixed regarding this in the prior version. I'd strongly recommend an upgrade of the cas module, at least to the 6.x-2 branch.

#9

Version:6.x-1.0» 6.x-2.1

i upgraded to 6.x-2.1 but am still having the issue

#10

Can you attempt to link to /cas instead of /login and see if that solves your problem?

#11

i did try linking to /cas. i also tried adding the "CAS User Login" block and logging in from there. still redirects to the home page for some reason!

#12

veeplus: This might be a duplicate of #1087770: Redirection to user page is forced on login. Can you confirm?

#13

I'm having this issue as well. Somehow visiting a 403 or 404 page sets $_SESSION['destination']. Then we never overwrite that, and after login, return to that...

Now drupal_not_found() has

<?php
 
// Keep old path for reference, and to allow forms to redirect to it.
 
if (!isset($_REQUEST['destination'])) {
   
$_REQUEST['destination'] = $_GET['q'];
  }
?>

but I'm not sure how $_REQUEST ends up in $_SESSION.

#14

Are you both running the custom_error module?

Found this reference:

#502628: $_SESSION['redirect'] causes login form to redirect to 404 pages

#15

#16

i'm not using the custom_error module. and for the other post (http://drupal.org/node/1087770), i searched cas.module for that line but it's not in there, so i guess that's not the problem. could it have something to do with this line in cas_login_page(): $destination = variable_get('site_frontpage', 'node'); . since in my case, users are getting redirected to the front page?

#17

@veeplus: Yes, but notice the lines below which then redirect the user to other locations if those options are set.

To debug you could put some debug statement in the if branches to see which (if any) are triggering.

In each you could add a line like
drupal_set_message('BLAH evaluated to true');

Or install the devel module and put in some dpm() calls, like

dpm($_REQUEST);
dpm($_SESSION);

#18

looks like it's hitting: elseif ($_REQUEST['destination']) {$destination = $_REQUEST['destination'];}

is there a way to print that $_REQUEST['destination']; in the drupal_set_message so i can see what it's getting?

i can't use the devel module because a past site maintainer said that it causes the site to crash.

#19

Sure, you can do something like

drupal_set_message('<pre>' . print_r($_REQUEST, TRUE) . '</pre>');

#20

If you don't mind hacking the code just do this

drupal_set_message($_REQUEST['destination']);

#21

i had tried the latter suggestion and i thought it didn't work because it was blank, but after seeing the whole array.. i think destination is just blank.

why would that happen? how is destination set?

#22

$_REQUEST is a combination of $_GET and $_POST and $_COOKIE (see http://us2.php.net/manual/en/reserved.variables.request.php).

You can try to print out those arrays to see which is setting 'destination'. Also, try searching through all of the source code of your site for 'destination' as that might give a hint as to which, if any, contributed module is setting it.

#23

Status:active» postponed (maintainer needs more info)

#24

Component:Code» CAS
Status:postponed (maintainer needs more info)» closed (cannot reproduce)

Please upgrade to 6.x-3.x and let us know if the problem persists.

#25

We have been on the 6.x-3.x line and still have the problem that has been identified. Here is the url when on the cas login page
https://cas.byu.edu/cas/login?service=http%3A%2F%2Ffinserve.byu.edu%2Fco...
The service url is pointing at the correct place to return but when you go back, it just takes you to the homepage.

#26

Status:closed (cannot reproduce)» active

I just noticed that this one had been closed. I am changing that but also have some additional info. The prod site referenced above has the page path listed in the cas settings to be protected and so when you click on the link it automatically takes you to the cas login page with the url above. However, the dev server hasn't been changed to have the page path listed in cas and so doesn't redirect on attempting to access the page. HOWEVER, when I click the cas login link at the top of the page (that points to /cas) it goes to this url:
https://cas.byu.edu/cas/login?service=http%3A%2F%2Ffinserve-dev.byu.edu%...
and when it gets back it returns to the CORRECT page. I wonder if you were to set the redirect on login to /cas if the problem would be fixed. I will try it and let you know.

#27

That works!! I put cas as the redirect to path and clicked the force redirect on initial login and now it redirects back to the page whose path was protected by the CAS module. Hope this helps someone out. Don't know what to set the status on this issue to now. Please feel free to do what you would like with it.

#28

Status:active» fixed

Glad to hear you got things working. I'm marking this as fixed. If others have this problem hopefully they can find it thru search.

#29

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.