在while循环内通过foreach循环设置cookie [英] setting cookie through foreach loop inside while loop

查看:61
本文介绍了在while循环内通过foreach循环设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试通过 while 循环 内的 foreach 循环 设置这些 cookie 时遇到错误.我得到的错误是 .... 注意:
中遇到格式不正确的数值php脚本:

I am getting an error while trying to set these cookies through a foreach loop inside a while loop. The error I am getting is .... Notice: A non well formed numeric value encountered in
php script:

while($row = mysql_fetch_array($sql)){
            $path = "/";
            $expire =  time() + 2592000;
            $expire =  date("Y-m-d h:i:s",$expire);
            $c = array(
            md5('id')=>$row['id'],
            md5('name')=>$row['u'],
            md5('sex')=>$row['s'],
            md5('country')=>$row['co'],
            md5('state')=>$row['st'],
            md5('city')=>$row['ci'],
            md5('timezone')=>$row['ti']
            );
            foreach($c as $name=>$value){
                setcookie($name,$value,$expire,$path);
            }
            echo "Logging you in! <img src=\"source/image/50gl.gif\"><br>"; 
        }

推荐答案

$expire 应为 int.你有一个字符串.这行是不必要的,问题原因:

$expire is expected to be an int. You have a string. This line is unnecessary, and the cause of the problem:

$expire =  date("Y-m-d h:i:s",$expire);

http://us3.php.net/setcookie

您可能会注意到 expire 参数采用 Unix 时间戳,而不是日期格式 Wdy, DD-Mon-YYYY HH:MM:SS GMT,这是因为 PHP 在内部进行了这种转换.

You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally.

这篇关于在while循环内通过foreach循环设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆