douluan8828 2011-03-20 16:09
浏览 94

这是设置cookie的正确方法吗?

// if login is ok then we add a cookie

         $_POST['user_name'] = stripslashes($_POST['user_name']); 

          $hour = time() + 3600; 

             setcookie(ID_my_site, $_POST['user_name'], $hour); 

            setcookie(Key_my_site, $_POST['password'], $hour);   

Is this a right way to set cookies? Its been causing me serious redirect errors. See here: PHP Redirect problem with subdomain

  • 写回答

2条回答 默认 最新

  • doucheng9058 2011-03-20 16:10
    关注

    No, strings need to be quoted (use error_reporting(E_ALL); to get warnings about bad things like unquoted strings).

    setcookie('ID_my_site', $_POST['user_name'], $hour);
    setcookie('Key_my_site', $_POST['password'], $hour);
    

    Besides that, if you have to apply stripslashes() to your GPC data, your server configuration is horrible. magic_quotes_gpc should be disabled. Also, only use stripslashes if get_magic_quotes_gpc() is true. Otherwise you must not use stripslashes on GPC data.

    Additionally, storing plaintext passwords in cookies is an extremely bad thing! While browsers usually encrypt stored passwords, cookies are not encrypted.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable