0

On my site I have a private page that can only be accessed when the user is logged in. If they aren't logged in they are directed to the login page.

I want to redirect them back to that page after they've logged in

I've tried a lot of solutions already listed on here including: logindestination and logintoboggan.

Every time the person logs in they are always directed to their user page no matter what I change in logintoboggan/logindestination

I tried creating a rule but was getting a 404. I'm not sure what to put in the PHP Evaluation field in the redirect action.

I've added this to my template file

global $user;
    if ($user->uid == 0){
        print l("Login","user/login",array('query' =>     drupal_get_destination()));
    }
else{
print l("Logout","user/logout",array('query' => drupal_get_destination()));
}   

And then in logindestination I added

$destination = drupal_get_destination();
print $destination;

What am I doing wrong??

  • On my site I have a private page that can only be accessed when the user is logged in. Just to understand, I have one question. What is the meaning of private page here? If it is viewable by non-logged in user, how can it be private. You mean that, non-logged in user can view but cannot comment? – CodeNext Jul 18 '16 at 10:02
  • The page being private means that the user must be logged in to access. – Stephen O'Connell Jul 18 '16 at 10:09
  • Would you let me know which module did you use to make the private page. Why I am asking so I can try on my trial site. As this issue I faced and I came up with solution with logindestination+logintoboggan. Because my solution can work on normal page for comment access but might not work on page which is entirely non-accessible. I guess, you have set a page, which states like "Login to access this page". – CodeNext Jul 18 '16 at 10:23
  • I didn't use a module to make the page private. I wrote the code myself for this. function formtest_user_logged_in(){ if(user_is_logged_in()){ drupal_goto('form'); } else { drupal_goto('user?destination=form'); } } – Stephen O'Connell Jul 18 '16 at 10:30
  • 1
    I can't figure it out, sorry. – CodeNext Jul 18 '16 at 12:01
2

For logindestination to work properly all you need to do is add an entry using <current> as the redirect location. Leave the "Redirect to Page" option as Internal page or external URL. This configuration will send a user back to the page they were trying to access before being sent to the login page.

enter image description here

| improve this answer | |
  • I ended up changing my code on my custom page so that the access control is 'user_is_logged_in'. This fixed the issue I was having with LoginToboggan and now everythiing is working perfectly. Thanks for the help – Stephen O'Connell Jul 25 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.