du155305 2014-04-05 11:21
浏览 145
已采纳

在Laravel 4.1中使用cookie重定向

I am trying to drop a cookie for a specific view, so that a user can only visit that page once. However, what I have now is not redirecting the user away from the view on repeated viewings like I want. Here is what I have:

public function getWelcome() {
            // Drop cookies and check for it...

            $cookie =  Cookie::get('cs_welcome');

            if(isset($cookie) && $cookie == 1) {
                return Redirect::to('/fans/'.Auth::user()->url_tag);
            }
            else {
                $cookie = Cookie::forever('cs_welcome', 1);
            }

            return View::make('fans.welcome');

Basically I want them to only see the fans.welcome view once. If it is a repeated visit, I want them to go to /fans/Auth::user()->url_tag. Is there something I'm missing here? Thank you for your help.

  • 写回答

2条回答 默认 最新

  • dongwen4630 2014-04-05 11:34
    关注

    IMO I believe that with that approach a user can wipe their navigation cookies and then when they go into their account they we'll se the welcome page again.

    To have a real persistence that the user saw the welcome screen I recommend that you save that information in your database and relate that to the user.

    Let's say $user->sawWelcomePage = true

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部