Php 用户登录数据库中的更新会话id后

Php 用户登录数据库中的更新会话id后,php,authentication,Php,Authentication,每次用户登录到我的页面时,我都需要更新数据库中的会话id。因此,它保存了保存在变量$sesId中的用户的活动会话。我试过了,但没用 <?php session_start(); // Change this to your connection info. $DATABASE_HOST = 'localhost'; $DATABASE_USER = 'USer1'; $DATABASE_PASS = 'BBHHJJ'; $DATABASE_NAME = 'database'; $email

每次用户登录到我的页面时,我都需要更新数据库中的会话id。因此,它保存了保存在变量$sesId中的用户的活动会话。我试过了,但没用

<?php
session_start();
// Change this to your connection info.
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'USer1';
$DATABASE_PASS = 'BBHHJJ';
$DATABASE_NAME = 'database';
$email = $_POST['email'];
$hash = password_hash($password, PASSWORD_DEFAULT);


// Creating a connection
$conn = new mysqli($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
// Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
  echo "Connected successfully";



// Prepare our SQL, preparing the SQL statement will prevent SQL injection.
if ($stmt = $conn->prepare('SELECT id, password, Status, linkPersoonlijkplan , PersoonlijkPlan FROM accounts WHERE username =? ')) {
    
    $stmt->bind_param('s', $_POST['username']);
    $stmt->execute();
    // Store the result so we can check if the account exists in the database.
    $stmt->store_result();
    echo "check";
    }
else{
header("location:inlogF2.php");
}

    if ($stmt->num_rows > 0) {
    $stmt->bind_result($id, $password, $Status, $linkPersoonlijkplan,$PersoonlijkPlan);
            
    $stmt->fetch();
    
    if (password_verify($_POST['password'], $password)) {
            
        session_regenerate_id();
        $_SESSION['loggedin'] = TRUE;
        $_SESSION['name'] = $_POST['username'];
        $_SESSION['id'] = $id;
        $_SESSION['Status'] = $Status;
        $_SESSION['pw'] = $password;
        $_SESSION['linkPersoonlijkplan'] = $linkPersoonlijkplan;
        $_SESSION['Ingelogd'] = "1";
        $_SESSION['PersoonlijkPlan'] = $PersoonlijkPlan;
        echo 'Welcome ' . $_SESSION['name'] . '!';
        $sesId = session_id();

        $stmt = $conn->mysqli->prepare("UPDATE accounts SET sessie=? WHERE id=?");
        $stmt->bind_param('s', $sesId, $id);
        $stmt->execute();
        
        header("location:homepage.php");
        
    } else {
        $_SESSION['fout'] = "3";
        echo 'Incorrect password!';
        header("location:inlogF.php");
    }
} else {
        header("location:inlogF2.php");
}
$stmt->close();




?>


在更新中将s更改为ss,并删除了mysqli->,现在可以使用了

需要在
$stmt->bind_参数('ss',$sesId,$id)中添加一个额外的
s
您需要停止手动检查错误。请阅读:你试着检查一下为什么这不起作用?在更新中更改了ss并删除了mysqli->,它起作用了