Cookie不保存(PHP)

时间:2018-02-11 17:47:52

标签: php cookies web

我的cookie没有保存,我使用的是PHP 5。 码:     

require 'dbcon.php';
$sql = "SELECT * FROM accounts";
$result = $conn->query($sql);
$username = $_POST['username'];
$password = $_POST['password'];
$row = mysql_fetch_row($result);

setcookie("ID6", $row['ID'], time() + 60*60*24*31*12, "/") or die("Cookie could not be set. <a href='index.php'>Try again!</a>"); 

if(!isset($_POST['username']) || !isset($_POST['password'])) {
    header("Location: index.php");
    exit();
}
 while($row = mysqli_fetch_assoc($result)) {
    if($username == $row['username']) {
        if($password == $row['password']) {

        if($row['accdel'] == 1) {
            echo("You are banned.");
            exit(); 
            }
            echo "Logged in with cookie:" . $_COOKIE['ID6'];
            exit();

        }
        else {
            echo "The account does not exist, or you have put in the wrong log in.";
            exit();
        echo"That's not an account name though...";}
    }
}


?>

请帮忙。所选的sql是否甚至是可设置的cookie值? (请说明一点。我对php和cookies都不太了解。

2 个答案:

答案 0 :(得分:0)

https://www.jqueryscript.net/other/E-commerce-Cart-Plugin-For-jQuery.html

我尝试用PHP保存cookie很多天都没用。 也许试试jquery。

答案 1 :(得分:0)

ID未从数据库中获取,因为它不在while循环中。