duangu6588 2014-09-16 17:39
浏览 46

如何设置cookie以及该cookie是否已存在或不做某事

How to do something like this with cookies?

If a cookie exists, redirect user to a last used URL on a site or a homepage.

If not, create a cookie + redirect to specific page with registration form.

Can you check if this php-code is doing this as defined above?

<?php
if(!isset($_COOKIE['firsttime'])) {
?>
<meta http-equiv="refresh" content="0; url=http://example.com/">
<?php
} else {
setcookie('firsttime',time() + (86400 * 7));
?>
<meta http-equiv="refresh" content="0; url=http://example.com/"> // redirecrting to registratio form
<?php
}
?>
  • 写回答

1条回答 默认 最新

  • duanpai1920 2014-09-16 17:50
    关注

    You should consider to use a php request rather than an meta tag because its more seamless for the end use. Check out this Thread: https://stackoverflow.com/a/768472/4043299

    If you want more then user redircetion e.g. store login of user you should use PHP Sessions. With PHP Sessions you can safely storage data which is assigned to the users active ssesion.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog