du155305 2014-04-05 19: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 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

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

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊