Laravel - how to redirect users to previous page, with hash from previous page?
When users login, I'd like them to be redirected to the page they were on before, with the same hash that they had from that page.
E.g. if they were on x.com/x#abc
and log in, they should be redirected back to x.com/x#abc
I'm using AJAX successfully to store the hash value upon login, to the Session:
Session::put('login_hash', $_POST['hash']);
I'm then trying to adjust the code in RedirectsUsers.php
to append this hash value, however, this doesn't work as the Session::get('login_hash')
is always blank.
I've checked through other views etc and see that Session::get('login_hash')
is actually filled correctly, it's just that RedirectsUsers.php
can't seem to access this value, so after logging in, the user just goes to x.com/x
rather than x.com/x#abc
Not sure if "Use Session" is the right thing to include, given that this RedirectsUsers file is in a vendor folder?
Any help would be much appreciated. I'm on Laravel 5.6.
<?php
namespace IlluminateFoundationAuth;
use Input, Redirect, URL;
use Session;
trait RedirectsUsers
/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
if (Auth::user()->user_type=='admin')
$suffix = !empty(Session::get('login_hash')) ? '#' . Session::get('login_hash') : '';
return '/admin/home' . $suffix;
laravel laravel-5.6
add a comment |
When users login, I'd like them to be redirected to the page they were on before, with the same hash that they had from that page.
E.g. if they were on x.com/x#abc
and log in, they should be redirected back to x.com/x#abc
I'm using AJAX successfully to store the hash value upon login, to the Session:
Session::put('login_hash', $_POST['hash']);
I'm then trying to adjust the code in RedirectsUsers.php
to append this hash value, however, this doesn't work as the Session::get('login_hash')
is always blank.
I've checked through other views etc and see that Session::get('login_hash')
is actually filled correctly, it's just that RedirectsUsers.php
can't seem to access this value, so after logging in, the user just goes to x.com/x
rather than x.com/x#abc
Not sure if "Use Session" is the right thing to include, given that this RedirectsUsers file is in a vendor folder?
Any help would be much appreciated. I'm on Laravel 5.6.
<?php
namespace IlluminateFoundationAuth;
use Input, Redirect, URL;
use Session;
trait RedirectsUsers
/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
if (Auth::user()->user_type=='admin')
$suffix = !empty(Session::get('login_hash')) ? '#' . Session::get('login_hash') : '';
return '/admin/home' . $suffix;
laravel laravel-5.6
Are you getting logged in using ajax?
– linktoahref
Nov 13 '18 at 4:21
@linktoahref no it's just via a standard PHP POST
– user6122500
Nov 13 '18 at 5:21
where exactly is the ajax being fired?
– linktoahref
Nov 13 '18 at 5:37
As the hash is usually never transferred to the server, you can't access it there. Or do you have some JS code in place that reads the hash and places it into a input field?
– Nico Haase
Nov 13 '18 at 7:32
@linktoahref AJAX is being fired upon the login page being loaded. I can see by testing on other URLs that the Session variable is being stored correctly
– user6122500
Nov 13 '18 at 9:40
add a comment |
When users login, I'd like them to be redirected to the page they were on before, with the same hash that they had from that page.
E.g. if they were on x.com/x#abc
and log in, they should be redirected back to x.com/x#abc
I'm using AJAX successfully to store the hash value upon login, to the Session:
Session::put('login_hash', $_POST['hash']);
I'm then trying to adjust the code in RedirectsUsers.php
to append this hash value, however, this doesn't work as the Session::get('login_hash')
is always blank.
I've checked through other views etc and see that Session::get('login_hash')
is actually filled correctly, it's just that RedirectsUsers.php
can't seem to access this value, so after logging in, the user just goes to x.com/x
rather than x.com/x#abc
Not sure if "Use Session" is the right thing to include, given that this RedirectsUsers file is in a vendor folder?
Any help would be much appreciated. I'm on Laravel 5.6.
<?php
namespace IlluminateFoundationAuth;
use Input, Redirect, URL;
use Session;
trait RedirectsUsers
/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
if (Auth::user()->user_type=='admin')
$suffix = !empty(Session::get('login_hash')) ? '#' . Session::get('login_hash') : '';
return '/admin/home' . $suffix;
laravel laravel-5.6
When users login, I'd like them to be redirected to the page they were on before, with the same hash that they had from that page.
E.g. if they were on x.com/x#abc
and log in, they should be redirected back to x.com/x#abc
I'm using AJAX successfully to store the hash value upon login, to the Session:
Session::put('login_hash', $_POST['hash']);
I'm then trying to adjust the code in RedirectsUsers.php
to append this hash value, however, this doesn't work as the Session::get('login_hash')
is always blank.
I've checked through other views etc and see that Session::get('login_hash')
is actually filled correctly, it's just that RedirectsUsers.php
can't seem to access this value, so after logging in, the user just goes to x.com/x
rather than x.com/x#abc
Not sure if "Use Session" is the right thing to include, given that this RedirectsUsers file is in a vendor folder?
Any help would be much appreciated. I'm on Laravel 5.6.
<?php
namespace IlluminateFoundationAuth;
use Input, Redirect, URL;
use Session;
trait RedirectsUsers
/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
if (Auth::user()->user_type=='admin')
$suffix = !empty(Session::get('login_hash')) ? '#' . Session::get('login_hash') : '';
return '/admin/home' . $suffix;
laravel laravel-5.6
laravel laravel-5.6
edited Nov 13 '18 at 9:54
user6122500
asked Nov 13 '18 at 4:04
user6122500user6122500
16714
16714
Are you getting logged in using ajax?
– linktoahref
Nov 13 '18 at 4:21
@linktoahref no it's just via a standard PHP POST
– user6122500
Nov 13 '18 at 5:21
where exactly is the ajax being fired?
– linktoahref
Nov 13 '18 at 5:37
As the hash is usually never transferred to the server, you can't access it there. Or do you have some JS code in place that reads the hash and places it into a input field?
– Nico Haase
Nov 13 '18 at 7:32
@linktoahref AJAX is being fired upon the login page being loaded. I can see by testing on other URLs that the Session variable is being stored correctly
– user6122500
Nov 13 '18 at 9:40
add a comment |
Are you getting logged in using ajax?
– linktoahref
Nov 13 '18 at 4:21
@linktoahref no it's just via a standard PHP POST
– user6122500
Nov 13 '18 at 5:21
where exactly is the ajax being fired?
– linktoahref
Nov 13 '18 at 5:37
As the hash is usually never transferred to the server, you can't access it there. Or do you have some JS code in place that reads the hash and places it into a input field?
– Nico Haase
Nov 13 '18 at 7:32
@linktoahref AJAX is being fired upon the login page being loaded. I can see by testing on other URLs that the Session variable is being stored correctly
– user6122500
Nov 13 '18 at 9:40
Are you getting logged in using ajax?
– linktoahref
Nov 13 '18 at 4:21
Are you getting logged in using ajax?
– linktoahref
Nov 13 '18 at 4:21
@linktoahref no it's just via a standard PHP POST
– user6122500
Nov 13 '18 at 5:21
@linktoahref no it's just via a standard PHP POST
– user6122500
Nov 13 '18 at 5:21
where exactly is the ajax being fired?
– linktoahref
Nov 13 '18 at 5:37
where exactly is the ajax being fired?
– linktoahref
Nov 13 '18 at 5:37
As the hash is usually never transferred to the server, you can't access it there. Or do you have some JS code in place that reads the hash and places it into a input field?
– Nico Haase
Nov 13 '18 at 7:32
As the hash is usually never transferred to the server, you can't access it there. Or do you have some JS code in place that reads the hash and places it into a input field?
– Nico Haase
Nov 13 '18 at 7:32
@linktoahref AJAX is being fired upon the login page being loaded. I can see by testing on other URLs that the Session variable is being stored correctly
– user6122500
Nov 13 '18 at 9:40
@linktoahref AJAX is being fired upon the login page being loaded. I can see by testing on other URLs that the Session variable is being stored correctly
– user6122500
Nov 13 '18 at 9:40
add a comment |
2 Answers
2
active
oldest
votes
try this one
$suffix = '#'.Session::get('login_hash');
return '/admin/home/' . $suffix;
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
add a comment |
You can try this:
return redirect(Redirect::back()->getTargetUrl(). $suffix);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273622%2flaravel-how-to-redirect-users-to-previous-page-with-hash-from-previous-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this one
$suffix = '#'.Session::get('login_hash');
return '/admin/home/' . $suffix;
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
add a comment |
try this one
$suffix = '#'.Session::get('login_hash');
return '/admin/home/' . $suffix;
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
add a comment |
try this one
$suffix = '#'.Session::get('login_hash');
return '/admin/home/' . $suffix;
try this one
$suffix = '#'.Session::get('login_hash');
return '/admin/home/' . $suffix;
answered Nov 13 '18 at 4:28
Sagar jadhavSagar jadhav
1
1
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
add a comment |
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
Can you add some explanation about this? To me, it looks pretty like the code in the question
– Nico Haase
Nov 13 '18 at 7:30
add a comment |
You can try this:
return redirect(Redirect::back()->getTargetUrl(). $suffix);
add a comment |
You can try this:
return redirect(Redirect::back()->getTargetUrl(). $suffix);
add a comment |
You can try this:
return redirect(Redirect::back()->getTargetUrl(). $suffix);
You can try this:
return redirect(Redirect::back()->getTargetUrl(). $suffix);
edited Nov 13 '18 at 4:40
answered Nov 13 '18 at 4:29
Anar BayramovAnar Bayramov
4,30942542
4,30942542
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273622%2flaravel-how-to-redirect-users-to-previous-page-with-hash-from-previous-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you getting logged in using ajax?
– linktoahref
Nov 13 '18 at 4:21
@linktoahref no it's just via a standard PHP POST
– user6122500
Nov 13 '18 at 5:21
where exactly is the ajax being fired?
– linktoahref
Nov 13 '18 at 5:37
As the hash is usually never transferred to the server, you can't access it there. Or do you have some JS code in place that reads the hash and places it into a input field?
– Nico Haase
Nov 13 '18 at 7:32
@linktoahref AJAX is being fired upon the login page being loaded. I can see by testing on other URLs that the Session variable is being stored correctly
– user6122500
Nov 13 '18 at 9:40