du155305
2014-04-05 19:21
浏览 140
已采纳

在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 19: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

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douguabu8960 2014-04-06 03:28

    You should use something like this:

    1. Register the user
    2. Login the user automatically after creating the account
    3. After login redirect to welcome page
    

    Also, if you don't want to log in a user automatically you may skip it.

    In both cases, keep a flag, any field in users table, for example: verified and by default keep it NULL once the use logs in then update the field with 1 or any truthy value so you may check if that field is NULL then the user should be in the welcome page otherwise don't let the user go to that page.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题