Làm cách nào để xóa phiên đăng nhập trong php?

0] { $con = mysqli_connect['127. 0. 0. 1. 3306','root','','admin'] or die['Không thể kết nối']; . $_POST["user_name"]. "' và mật khẩu = '". $_POST["mật khẩu"]. "'"]; . "; } } if[isset[$_SESSION["id"]]] { header["Vị trí. mục lục. php"]; } ?>Đăng nhập người dùng

Nhập chi tiết đăng nhập

Tên người dùng.

Mật khẩu


PHP có chức năng cốt lõi session_destroy[] để xóa tất cả các giá trị phiên. Đây là một hàm không đối số đơn giản trả về giá trị boolean true hoặc false

ID phiên PHP được lưu trữ trong cookie theo mặc định. Nói chung, tệp cookie phiên đó có tên là PHPSESSID. Hàm session_destroy sẽ không bỏ đặt id phiên trong cookie

Để hủy phiên 'hoàn toàn', ID phiên cũng phải được bỏ đặt

Ví dụ nhanh này sử dụng session_destroy[] để hủy phiên. Nó sử dụng phương thức set_cookie[] để hủy toàn bộ bằng cách hết hạn ID phiên PHP

The following code shows how the PHP session works. The function my_session_start[] does almost the same thing as session_start[].

error_reporting[E_ALL];
ini_set['display_errors', true];
ini_set['session.save_path', __DIR__];

my_session_start[];

echo '

session id: '.my_session_id[].'

';

echo '

________0';

$now = date['H:i:s'];
if [isset[$_SESSION['last_visit_time']]] {
  echo '

Last Visit Time: '.$_SESSION['last_visit_time'].'

';
}
echo '

Current Time: '.$now.'

';

$_SESSION['last_visit_time'] = $now;

function my_session_start[] {
  global $phpsessid, $sessfile;

  if [!isset[$_COOKIE['PHPSESSID']] || empty[$_COOKIE['PHPSESSID']]] {
    $phpsessid = my_base32_encode[my_random_bytes[16]];
    setcookie['PHPSESSID', $phpsessid, ini_get['session.cookie_lifetime'], ini_get['session.cookie_path'], ini_get['session.cookie_domain'], ini_get['session.cookie_secure'], ini_get['session.cookie_httponly']];
  } else {
    $phpsessid = substr[preg_replace['/[^a-z0-9]/', '', $_COOKIE['PHPSESSID']], 0, 26];
  }

  $sessfile = ini_get['session.save_path'].'/sess_'.$phpsessid;
  if [is_file[$sessfile]] {
    $_SESSION = unserialize[file_get_contents[$sessfile]];
  } else {
    $_SESSION = array[];
  }
  register_shutdown_function['my_session_save'];
}

function my_session_save[] {
  global $sessfile;

  file_put_contents[$sessfile, serialize[$_SESSION]];
}

function my_session_id[] {
  global $phpsessid;
  return $phpsessid;
}

function my_random_bytes[$length] {
  if [function_exists['random_bytes']] {
      return random_bytes[$length];
  }
  $randomString = '';
  for [$i = 0; $i < $length; $i++] {
      $randomString .= chr[rand[0, 255]];
  }
  return $randomString;
}

function my_base32_encode[$input] {
  $BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
  $output = '';
  $v = 0;
  $vbits = 0;
  for [$i = 0, $j = strlen[$input]; $i < $j; $i++] {
    $v > $vbits];
      $v &= [[1 0] {
    $v

Chủ Đề