用户在php中注销时打开或关闭状态

时间:2017-08-19 04:57:58

标签: php

我的代码有问题,我很困惑如何在代码上设置逻辑。 我想问一下这个问题,如何在每次点击用户帐户时设置状态,并将状态更改为“关闭”。

这是我的代码:

<?php
  session_start();

  include_once "config/db.php";

  $params = session_get_cookie_params();

  setcookie(session_name(), null, time()-48000,
            $params['path'], $params['domain'], $params['httponly']);

  session_destroy();

  $sql = "UPDATE user SET status 'off' WHERE user_id={$_SESSION['u_id']}";
  mysqli_query($connect, $sql);

  mysqli_close($connect);

  header("location: login.php");
  exit();

?>

2 个答案:

答案 0 :(得分:0)

在销毁会话之前,请编写更新查询

$sql = "UPDATE user SET status =  'off' WHERE user_id={$_SESSION['u_id']}";

session_destroy();

答案 1 :(得分:0)

您需要先更改订单,然后更新查询,然后销毁Cookie和会话

<?php
  session_start();

  include_once "config/db.php";

  $params = session_get_cookie_params();  

  $sql = "UPDATE user SET status = 'off' WHERE user_id={$_SESSION['u_id']}";
  mysqli_query($connect, $sql);

  mysqli_close($connect);

  setcookie(session_name(), null, time()-48000,
            $params['path'], $params['domain'], $params['httponly']);

  session_destroy();

  header("location: login.php");
  exit();

?>