在PHP中设置多个Cookie

编程入门 行业动态 更新时间:2024-10-14 06:21:52
本文介绍了在PHP中设置多个Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

感谢您的帮助。

我有一个检查登录名然后设置一些cookie的脚本。设置了4个cookie,(稍后我可能会将一些cookie移到服务器会话,但是现在我正在使用cookie。

I have a script that checks logins and then sets some cookies. There are 4 cookies that are being set, (later I will probably move some to server session but for now I am using cookies.

我遇到的问题是在执行脚本的其余部分之前,只设置了前4个中的前2个。有人可以看到原因吗?

The issue that I am having is that only the first 2 of the 4 are being set before the rest of the script is being executed. Can anyone see why?

// If there is a row, and only 1 row, then the details are correct. Set the cookie and re-direct $row = mysqli_fetch_array($data); setcookie('user_id', $row['User_ID'], time()+ (60*15),"/"); setcookie('user_name', $row['UserName'], time()+ (60*15),"/"); setcookie('access_Level', $row['Access_Level'], time()+ (60*15),"/"); setcookie('db_con', $row['Db_Con'], time()+ (60*15),"/"); $home_url = $link . "application/views/Dashboard.php"; header('Location: ' . $home_url);

推荐答案

使用:

<?php $row = array( 'User_ID' => '1', 'UserName' => '1', 'Access_Level' => '1', 'Db_Con' => '1' ); setcookie('user_id', $row['User_ID'], time()+ (60*15),"/"); setcookie('user_name', $row['UserName'], time()+ (60*15),"/"); setcookie('access_Level', $row['Access_Level'], time()+ (60*15),"/"); setcookie('db_con', $row['Db_Con'], time()+ (60*15),"/"); // This will not be set, and the cookie is not created. setcookie('db_con2', $row['Db_Con2'], time()+ (60*15),"/"); ?>

jfcoder/test/setcookie.php

在Firefox中,我检查了一下页面右侧的cookie。单击页面,查看页面信息,安全性选项卡,查看Cookie 按钮。所有四个Cookie都显示在我的浏览器的该页面上。最后一个没有(因为它没有价值)。

In Firefox, I check to see the cookies for a page by right-clicking on the page, View Page Info, Security tab, View Cookies button. All four cookies show up on that page in my browser. The last one does not (since it is has no value).

我认为您的列名没有正确拼写/大写或其他一些问题,那 $ row ['Access_Level'] 和 $ row ['Db_Con'] 是结果中的空列。

I'm thinking your column names are not spelled/capitalized correctly, or some other issue, and that $row['Access_Level'] and $row['Db_Con'] are empty columns in your result.

更多推荐

在PHP中设置多个Cookie

本文发布于:2023-05-29 03:37:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/335872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file &#039;D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!