簡體   English   中英

php會話不會破壞

[英]php Session doesn't destroy

我建立了一個網站,它有一個登錄表單,當用戶登錄時,登錄表單將不會出現,而注銷將顯示出來

我的問題是用戶退出會話時不會破壞

當用戶登錄時,我進入功能運行,當用戶退出時,我進入功能退出

HTML

<?php
        Session::init();
        $l = Session::get('loggedIn');
        if (isset($l) && $l==true) {
                ?>
        <a href="<?php echo URL; ?>login/signout" class="smallLink">sign out</a>
            <?php

        } else {
            ?>
            <a href="login/run">Sign in</a>
            <br/>
            <form action="<?php echo URL;?>login/run" method="POST">
                <div class="staticSignin">
                    phoneNumber
                    password
                </div>
                <div id="userInputSignin">
                    <input type="text" name="MNumber"/>
                    <input type="password" name="password"/>
                    <input type="image" src="http://localhost/Mar7ba/public/images/signinButton.png"/>
                </div>
            </form>
            <?php
        }
        ?>

運行登錄

Session::init();
            $row = $sth->fetch();
            $ID = $row['ID'];
            $rollID = $row['rollID'];
            Session::set('loggedIn', true);
            Session::set('ID', $ID);
            Session::set('roolOfUser', $rollID);

登出

 public function signout() {
        Session::set("loggedIn", false);
        Session::destroy();
        $this->view->render('index/index');
    }

會話課程

<?php

class Session {

    public static function init() {
        session_start();
    }

    public static function set($key, $value) {

        @$_SESSION[$key] = $value;
    }

    public static function get($key) {
        if (isset($_SESSION[$key]))
            return $_SESSION[$key];
    }

    public static function destroy() {
        unset ($_SESSION);
        session_destroy();
    }

}

退出時,登錄表單不會出現

要銷毀會話,您首先需要使用session_start()來啟動它,似乎您並沒有這樣做

嘗試這樣做:

session_start();

// Deleting all content in $_SESSION
$_SESSION = array();

// Destroying the session
session_destroy();

編輯1

嘗試在destroy()進行以下更改,以測試會話是否真正開始:

public static function destroy() {

    session_start();

    // Deleting all content in $_SESSION
    $_SESSION = array();

    // Destroying the session
    session_destroy();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM