Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:注销用户_Php_Html_Mysql_Logout - Fatal编程技术网

PHP:注销用户

PHP:注销用户,php,html,mysql,logout,Php,Html,Mysql,Logout,我有一个表单,允许用户输入他们的数据。然后,它将根据数据库检查这些数据,以查看用户是否存在。如果是这样,它会将它们记录到某个页面中 然后,我希望允许他们注销(这样他们就不再能够访问该页面)。为此,我创建了一个“logout.php”文档,试图在其中清除登录详细信息 但是,完成此操作后,如果我尝试加载登录页面,它会将我带回登录页面 以下是我的代码(login.php-创建表单并让用户登录): 试试这个: unset($_SESSION['username']); 它将从会话中删除用户名变量您需要

我有一个表单,允许用户输入他们的数据。然后,它将根据数据库检查这些数据,以查看用户是否存在。如果是这样,它会将它们记录到某个页面中

然后,我希望允许他们注销(这样他们就不再能够访问该页面)。为此,我创建了一个“logout.php”文档,试图在其中清除登录详细信息

但是,完成此操作后,如果我尝试加载登录页面,它会将我带回登录页面

以下是我的代码(login.php-创建表单并让用户登录):

试试这个:

unset($_SESSION['username']);

它将从会话中删除用户名变量

您需要销毁会话变量:

    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (ini_get("session.use_cookies")) {
        $params = session_get_cookie_params();
        setcookie(session_name(), '', time() - 42000,
            $params["path"], $params["domain"],
            $params["secure"], $params["httponly"]
        );
    }
    // Finally, destroy the session.
    session_destroy();
    $url = 'http://example.com';
    header( "Location: $url" );
    exit();
unset($_SESSION['username']);
    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (ini_get("session.use_cookies")) {
        $params = session_get_cookie_params();
        setcookie(session_name(), '', time() - 42000,
            $params["path"], $params["domain"],
            $params["secure"], $params["httponly"]
        );
    }
    // Finally, destroy the session.
    session_destroy();
    $url = 'http://example.com';
    header( "Location: $url" );
    exit();