The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Go to referring Page after login
#1
Hello,
I installed userspice on my project site and it is amazing!
I had a question, is there a way to have the landing page after login be the referring page?
Here is the workflow

User clicks on link to a member only page in email.
User is greeted to the login page because there are not logged in.
User logs in
User is taken to the link in email, not the default page for user permission level.

I'll be researching this, but was wondering if I didn't have to reinvent the wheel.

Thanks for your help in advance.
  Reply
#2
update: Still no solution, but I learned something!
I though I would use:
Code:
<?php echo $_SERVER['HTTP_REFERER']?>
the echo, was for testing purposes.
If I click on a link from somewhere within my site, the link is correct.
If I click a link from my email nothing is shown, I think that is by design from Referer.
Somehow I need to capture the page that sends a user to the login page in a variable, and then store that, then redirect that to var after logging in.

Will update if more information is found, thanks for listening!
  Reply
#3
I'm glad you like the project. I'm sure there is a way to accomplish what you're trying to accomplish.

I'm guessing what you want to do is to process that link with a get request. Can you give me an example of the types of links you're trying to send?

Also, you don't have to have only one login page. You could have something like custom_login.php that sends people different places after they login.
  Reply
#4
Hmm, my post didn't come through. I had been having the same thoughts lately. As mudmin said, if you had examples that would be great. I need to shoot mudmin for suggesting another login.php page Tongue

I have some thoughts on it. I'm assuming that you are talking about links to "private pages" that you might mail out, then after the user logs in, go to that link? I will try a few ideas out and let you know how it goes.
  Reply
#5
One issue is that the referrer gets set by the browser, so we might need to modify our securepage function to make that work by detecting where it was before...
  Reply
#6
Thanks for the quick reply.
I'm close to to getting a good solution working.
I'm setting a Session variable using
Code:
$_SESSION['actual_link'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

This variable is set on the private page I'm sending in an email. That piece of code is near the top of the page, just after require init.php, but before require header.
This allows the variable to be set, but the user still has to login to view the page.

After testing, it does look like the variable is being set correctly.
I'm now trying to send the user to that page in the custom_login_script.php but it's not working. The user just stays on an empty page after login.

This is what I have so Far
Code:
"User clicks on link to page_1 -> page_1 sets var to http://page_1 -> User is directed to login page -> User stays on a limbo page"

I tried doing the following in my custom login script and directly in my login page:
<pre>
Code:
if($user->data()->permissions !='2' || $user->data()->permissions !='3')
{
    if ($_SESSION['actual_link'] !=NULL){Redirect::to($_SESSION['actual_link'])}
    
}
    { Redirect::to('userhome.php'); }
else{header( 'Location: mainhomepage.php' );}
</pre>


Translating this code:
I have three levels of permissions
1 = user
2 = member
3 = Administrator
If person is a user take them to mainhomepage.php
If person is a member or admin take them to userhome.php
If person is a member or admin and they clicked on my emailed link, send them to the emailed link

Thanks for taking the time to read my notes!!

  Reply
#7
So I do have a solution that I have coded for UserSpice 5. It is pretty simple, but requires changes in a couple of places. It is somewhat similar to what you're doing, but it does it for any secured page. If you try to access a secured page without being logged in, it sends you to login.php. After the login, it sends you to the secured page you tried to access.

If you would like this rolled into a patch, I can talk to @mudmin and see what he things (he is handling most of the 4.1.x and 4.2 stuff right now). I think at minimum it should be able to make it into 4.2.
  Reply
#8
Sorry, I posted that I fixed my problem and not yours. I will see if I can rewrite it for the userspice 4.1.x or 4.2 stream. It may take a bit of time.
  Reply
#9
Hmm, I need to backtrack that I have it working as I wanted it to...I'll get back to you once things are clear for myself.
  Reply
#10
Here's for 4.1.5:

Changes to login.php:
http://pastebin.com/sEz1rzzw

I have shamelessly left in my plug for a login.php?err=My+Error+Message in the URL to allow users to be redirected back to login with a reported error. That is obviously unrelated to this problem/solution and can be left out (if you have to - grin).

Changes to us_helpers.php:
http://pastebin.com/wpdcHDSL

Note that I have my Redirect::to() function allowing an argument for the $_GET side of things. In vanilla US you would need to change

Code:
Redirect::to($us_url_root.'users/login.php', '?afterLoginGoto='.$_SERVER['PHP_SELF']);
to
Code:
Redirect::to($us_url_root.'users/login.php?afterLoginGoto='.$_SERVER['PHP_SELF']);

on line 395

For more details on the change to Redirect.php, you can see the code I posted earlier here:
http://pastebin.com/yvSx71U1
This change is *not* necessary in order to implement the changes above - you just have to modify the code as I have delineated. I'm just posting this extra reference to Redirect.php as a reminder of what change I was talking about.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)