Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Session can';重定向后无法访问会话数据_Session_Symfony_Symfony 2.1 - Fatal编程技术网

Session can';重定向后无法访问会话数据

Session can';重定向后无法访问会话数据,session,symfony,symfony-2.1,Session,Symfony,Symfony 2.1,我使用FOSUserBundle注册新用户 protected function authenticateUser(UserInterface $user, Response $response, $registration = false) { $expires = time() + 31536000; $secret = $this->container->getParameter('secret'); $

我使用FOSUserBundle注册新用户

protected function authenticateUser(UserInterface $user, Response $response, $registration = false)
    {         
        $expires = time() + 31536000;
        $secret = $this->container->getParameter('secret');
        $userClass = get_class($user);

        $value = base64_encode(implode(':', array(
            $userClass,
            base64_encode($user->getUsername()),
            $expires,  
            hash('sha256', $userClass.$user->getUsername().$expires.$user->getPassword().$secret)
            )));

        $response->headers->setCookie(
            new Cookie(
                'REMEMBERME',
                $value,
                $expires
            )
        );   

        try
        {
            $this->container->get('fos_user.security.login_manager')->loginUser(
                    $this->container->getParameter('fos_user.firewall_name'), $user, $response);

        }
        catch (AccountStatusException $ex)
        {
            // We simply do not authenticate users which do not pass the user
            // checker (not enabled, expired, etc.).
        }

        if($registration)
        {
            /*
             * remove the recommendation cookie
             */
            if ($this->container->get('request')->cookies->get('recommendCookie'))
            {
                $cookie = new Cookie('recommendCookie', '_______', time() - 100);

                $response->headers->setCookie($cookie);
            }            

        }
        return $response;
    }   
用户回答几个保存到会话中的问题。如果答案正确,用户将被重定向到注册操作。注册后,用户将被重定向到finalAction。 在finalAction中,我无法访问会话中的数据,但当我重新加载页面时,数据就在那里

protected function authenticateUser(UserInterface $user, Response $response, $registration = false)
    {         
        $expires = time() + 31536000;
        $secret = $this->container->getParameter('secret');
        $userClass = get_class($user);

        $value = base64_encode(implode(':', array(
            $userClass,
            base64_encode($user->getUsername()),
            $expires,  
            hash('sha256', $userClass.$user->getUsername().$expires.$user->getPassword().$secret)
            )));

        $response->headers->setCookie(
            new Cookie(
                'REMEMBERME',
                $value,
                $expires
            )
        );   

        try
        {
            $this->container->get('fos_user.security.login_manager')->loginUser(
                    $this->container->getParameter('fos_user.firewall_name'), $user, $response);

        }
        catch (AccountStatusException $ex)
        {
            // We simply do not authenticate users which do not pass the user
            // checker (not enabled, expired, etc.).
        }

        if($registration)
        {
            /*
             * remove the recommendation cookie
             */
            if ($this->container->get('request')->cookies->get('recommendCookie'))
            {
                $cookie = new Cookie('recommendCookie', '_______', time() - 100);

                $response->headers->setCookie($cookie);
            }            

        }
        return $response;
    }   
有人知道怎么了吗

protected function authenticateUser(UserInterface $user, Response $response, $registration = false)
    {         
        $expires = time() + 31536000;
        $secret = $this->container->getParameter('secret');
        $userClass = get_class($user);

        $value = base64_encode(implode(':', array(
            $userClass,
            base64_encode($user->getUsername()),
            $expires,  
            hash('sha256', $userClass.$user->getUsername().$expires.$user->getPassword().$secret)
            )));

        $response->headers->setCookie(
            new Cookie(
                'REMEMBERME',
                $value,
                $expires
            )
        );   

        try
        {
            $this->container->get('fos_user.security.login_manager')->loginUser(
                    $this->container->getParameter('fos_user.firewall_name'), $user, $response);

        }
        catch (AccountStatusException $ex)
        {
            // We simply do not authenticate users which do not pass the user
            // checker (not enabled, expired, etc.).
        }

        if($registration)
        {
            /*
             * remove the recommendation cookie
             */
            if ($this->container->get('request')->cookies->get('recommendCookie'))
            {
                $cookie = new Cookie('recommendCookie', '_______', time() - 100);

                $response->headers->setCookie($cookie);
            }            

        }
        return $response;
    }   
my registerAction()中的部分代码

protected function authenticateUser(UserInterface $user, Response $response, $registration = false)
    {         
        $expires = time() + 31536000;
        $secret = $this->container->getParameter('secret');
        $userClass = get_class($user);

        $value = base64_encode(implode(':', array(
            $userClass,
            base64_encode($user->getUsername()),
            $expires,  
            hash('sha256', $userClass.$user->getUsername().$expires.$user->getPassword().$secret)
            )));

        $response->headers->setCookie(
            new Cookie(
                'REMEMBERME',
                $value,
                $expires
            )
        );   

        try
        {
            $this->container->get('fos_user.security.login_manager')->loginUser(
                    $this->container->getParameter('fos_user.firewall_name'), $user, $response);

        }
        catch (AccountStatusException $ex)
        {
            // We simply do not authenticate users which do not pass the user
            // checker (not enabled, expired, etc.).
        }

        if($registration)
        {
            /*
             * remove the recommendation cookie
             */
            if ($this->container->get('request')->cookies->get('recommendCookie'))
            {
                $cookie = new Cookie('recommendCookie', '_______', time() - 100);

                $response->headers->setCookie($cookie);
            }            

        }
        return $response;
    }   
下面是authenticateUser方法

protected function authenticateUser(UserInterface $user, Response $response, $registration = false)
    {         
        $expires = time() + 31536000;
        $secret = $this->container->getParameter('secret');
        $userClass = get_class($user);

        $value = base64_encode(implode(':', array(
            $userClass,
            base64_encode($user->getUsername()),
            $expires,  
            hash('sha256', $userClass.$user->getUsername().$expires.$user->getPassword().$secret)
            )));

        $response->headers->setCookie(
            new Cookie(
                'REMEMBERME',
                $value,
                $expires
            )
        );   

        try
        {
            $this->container->get('fos_user.security.login_manager')->loginUser(
                    $this->container->getParameter('fos_user.firewall_name'), $user, $response);

        }
        catch (AccountStatusException $ex)
        {
            // We simply do not authenticate users which do not pass the user
            // checker (not enabled, expired, etc.).
        }

        if($registration)
        {
            /*
             * remove the recommendation cookie
             */
            if ($this->container->get('request')->cookies->get('recommendCookie'))
            {
                $cookie = new Cookie('recommendCookie', '_______', time() - 100);

                $response->headers->setCookie($cookie);
            }            

        }
        return $response;
    }   

你能给我们看一些代码的相关部分吗?你的代码中没有对会话的引用,我们帮不了你。你在哪里用它?