“Logout PHP” Kod odpowiedzi

wyloguj się w PHP

<?php
if(isset($_GET['logout'])) {
    session_destroy();
    unset($_SESSION['uname']);
    header('location:login.php');
}
?>
Mr. Samy

wyloguj się w PHP

if(isset($_GET['logout'])) {
    session_destroy();
    unset($_SESSION['username']);
    header('location:login.php');
}
Navbro

Logout PHP

<?php

ob_start();
if (!isset($_SESSION))
    session_start();
unset($_SESSION['user_id']);
session_destroy();
header("location:index.php");
Terrible Tiger

Logout kod PHP

<?php
  // If the user is logged in, delete the session vars to log them out
  session_start();
  if (isset($_SESSION['user_id'])) {
    // Delete the session vars by clearing the $_SESSION array
    $_SESSION = array();

    // Delete the session cookie by setting its expiration to an hour ago (3600)
    if (isset($_COOKIE[session_name()])) {      setcookie(session_name(), '', time() - 3600);    }

    // Destroy the session
    session_destroy();
  }

  // Delete the user ID and username cookies by setting their expirations to an hour ago (3600)
  setcookie('user_id', '', time() - 3600);
  setcookie('username', '', time() - 3600);

  // Redirect to the home page
  $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
  header('Location: ' . $home_url);
?>
Magnificent Mallard

Odpowiedzi podobne do “Logout PHP”

Pytania podobne do “Logout PHP”

Więcej pokrewnych odpowiedzi na “Logout PHP” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu