dongye9453 2011-12-02 20:49
浏览 295
已采纳

使用cookie跳过登录页面

I have a landing page that I would like viewers to see when first arriving at //domain.com. Then, if they have been to the site before the browser would automatically skip the landing page and take them directly to //domain.com/main.html

What is the best approach to do this?

  • 写回答

2条回答 默认 最新

  • douti6740 2011-12-02 20:55
    关注

    If I were you, I would actually re-direct if they haven't seen the page the first time. It creates a more intuitive URL.

    Either way, strictly speaking, you want to use setcookie the first time that the person visits the site, and then test to see if the value exists in $_COOKIE upon return. Realistically, you probably want:

    1. Redirect if cookie not present
    2. Link on landing page re-directs them to a page which sets the cookie.
    3. Page which sets the cookie re-directs them to the actual main page.

    Why do you want to set the value after the use clicks a link? Well, that way you can force them to actually look at the page before continuing, and I think that is more what you want.

    Your redirect might look like:

    if( !isset( $_COOKIE[ 'seen_landing_page' ] ) )
    {
        header( 'Location: <other page>' );
        die();
    }
    // do whatever else here.
    

    You can then have a simple pass-through page:

    setcookie('seen_landing_page',TRUE);
    header( 'Location: <your main page>' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置