Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2014-07-05 07:58:41

mickzerofive
Member
Registered: 2014-05-31
Posts: 15

login/logout redirecting

Hey guys,

So i have coded a login/logout script for my page which calls the forums/login.php
However, the only way I can find to redirect after the login is through this code


<input type="hidden" name="redirect_url" value="/home.php" />

Basically, what I want is to be able to redirect the user to the page they came from.

Reason behind this. Say a user is browsing the page and wanting to login on another page (other then the home screen), after they login they will be redirected back to the home page. Which can be rather annoying.

Is there a value I can put in to redirect back to the previous page, or can I put the PHP command
header('Location: ' . $_SERVER['HTTP_REFERER']);

somewhere in the fluxbb code?

Last edited by mickzerofive (2014-07-05 08:01:37)

Offline

#2 2014-07-05 09:59:20

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,670
Website

Re: login/logout redirecting

Redirecting to the referrer would send you to login.php again.

Why not fill the hidden redirect_url field on your login form with the referrer? You only need to make sure it is a proper forum URL, you don't want to redirect to some non-forum link...


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#3 2014-07-06 10:04:18

mickzerofive
Member
Registered: 2014-05-31
Posts: 15

Re: login/logout redirecting

Sorry, I am only newish to coding.

When you say fill the hidden redirect_url field on my login form with the referrer. What do you mean?
What would i put as the value in this code <input type="hidden" name="redirect_url" value="/home.php" /> ?

Also Why do I not want to redirect to a non-forum link? Why should I not redirect them back to the page they originated?

Last edited by mickzerofive (2014-07-06 10:04:50)

Offline

#4 2014-07-06 20:56:07

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,670
Website

Re: login/logout redirecting

Is your login form in a PHP file? Then you can do something along the lines of this:

<input type="hidden" name="redirect_url" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" />

fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#5 2014-07-07 03:34:55

mickzerofive
Member
Registered: 2014-05-31
Posts: 15

Re: login/logout redirecting

Found the solution for Part 1:
$returnurl = $_SERVER['REQUEST_URI'];
$returnget = $_SERVER['QUERY_STRING'];
$returnto = $returnurl . $returnget;
echo('<input type="hidden" name="redirect_url" value="'.$returnto.'" />');

Still need help with Part 2:
Also I'm not sure what i'm going to do about my logout script as I don't call a form like I do in the login. Can I change the below line of code to make it submit a form like with the login?

echo('<a href="/forums/login.php?action=out&amp;id='.$pun_user['id'].'&amp;csrf_token='.pun_hash($pun_user['id'].pun_hash(get_remote_address())).'"><div class="loginfields">LOG OUT</div></a>');

otherwise can i some-other way parse a redirect_url value with my current log out script?

Last edited by mickzerofive (2014-07-07 04:40:12)

Offline

#6 2014-07-07 11:57:28

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,670
Website

Re: login/logout redirecting

mickzerofive wrote:

Still need help with Part 2:
Also I'm not sure what i'm going to do about my logout script as I don't call a form like I do in the login. Can I change the below line of code to make it submit a form like with the login?

echo('<a href="/forums/login.php?action=out&amp;id='.$pun_user['id'].'&amp;csrf_token='.pun_hash($pun_user['id'].pun_hash(get_remote_address())).'"><div class="loginfields">LOG OUT</div></a>');

otherwise can i some-other way parse a redirect_url value with my current log out script?

You can wrap it in a form, just make sure that the "method" attribute is set to "GET".

To provide a custom redirect URL, you would have to change this line in login.php.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#7 2014-07-10 04:43:44

mickzerofive
Member
Registered: 2014-05-31
Posts: 15

Re: login/logout redirecting

Thanks again Franz. I'll give it ago over the weekend and see how it turns out smile

Offline

#8 2015-04-20 12:14:29

sandeepm
New member
Registered: 2015-04-20
Posts: 1

Re: login/logout redirecting

header("Location: " . BASE_URL . "home/index");
try this

Offline

Board footer

Powered by FluxBB