我从我的数据库中获取数据并尝试使用mysqli_fetch_assoc($ result)将它们放入cookie中。
最后,setcookie功能不起作用。 这是我的代码:
<?php
if(!isset($_POST['remember']) && !isset($_COOKIE['ProfileData']))
{
session_start();
}
else if(isset($_POST['remember']))
{
$remember = $_POST['remember'];
}
if (!isset($_SESSION['ProfileData']) && !isset($_COOKIE['ProfileData']))
{
$username = $_POST['username'];
$password = $_POST['password'];
}
$birthday = "DATE_FORMAT(Birthday, '%d/%m/%Y')";
if (!isset($username) && !isset($_SESSION['ProfileData']) && !isset($_COOKIE['ProfileData']))
{
header("location: /login.php");
}
else if(isset($username))
{
$con = mysqli_connect('localhost','root','root','Signum','3306');
$sql = "SELECT Id, Name, Surname, $birthday, Genre, Username FROM MyTable WHERE Username = '$username' and Password = '$password'";
$result = mysqli_query($con,$sql);
if(isset($remember))
{
setcookie("ProfileData", mysqli_fetch_assoc($result), time()+(60*60*24*365));
}
else
{
$_SESSION['ProfileData'] = mysqli_fetch_assoc($result);
}
}
?>
答案 0 :(得分:-1)