Pass parameters when redirecting

I have a scenario where a user clicks on an email link that requires login. If there is a link http://test.url.com/product/2, the user must be logged in, and the page should be redirected to the same path after authentication.

I tried to solve this problem with the help print_r($request->headers->get('referer'));in which the question was posed: Redirect the URL of the link (s) . which was unsuccessful since it returned null.

My next goal is to pass the parameters to the login page depending on the URL.

for example: if the user clicks http://test.url.com/product/2, the sign in the URL will look like http://test.url.com/signin/product/2or http://test.url.com/signing?=pruduct?2or something like this when the system redirects the user to the desired page.

Any document / example for passing parameters from the configuration level is very appreciated as I am very new to this domain. thank:)

0
source share
2 answers

I would suggest specifying the redirect URL as the query string in the login url, for example

http://test.url.com/signin/?redirect=http://test.url.com/product/2

After successfully logging in, all you have to do is

$url=$_GET['redirect'];
header("location:".$url);
+1
source

Does this help you?

public function productAction($id, Request $request){
    $url = $this->container->get("router")->generate("product_route", array("id" => $id));

    /** @var $session Session */
    $session = $request->getSession();
    $session->set("redirect_url", $url);
}         

public function signinAction(Request $request){
    // do your stuff

    /** @var $session Session */
    $session = $request->getSession();
    if ($session->has("redirect_url")){
        return new RedirectResponse($session->get("redirect_url");
    }
}   
0
source

All Articles