在 PHP 中设置多个 Cookie

Pau*_*ers 5 php cookies

感谢您对此提供帮助。

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

我遇到的问题是,在执行脚本的其余部分之前,仅设置了 4 个中的前 2 个。谁能看出为什么?

// 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);
Run Code Online (Sandbox Code Playgroud)

Jar*_*ish 4

使用:

<?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),"/");

?>
Run Code Online (Sandbox Code Playgroud)

http://jfcoder.com/test/setcookie.php

在 Firefox 中,我通过右键单击页面、选项卡、按钮来查看页面View Page InfoSecuritycookie View Cookies。所有四个 cookie 都显示在我的浏览器的该页面上。最后一个没有(因为它没有价值)。

我认为您的列名称拼写/大写不正确,或者存在其他问题,并且结果中的$row['Access_Level']和是空列。$row['Db_Con']