2016-05-15 58 views
-1

我目前正在開發基於Mini2 PHP框架的新項目 (here is the GitHub of the framework)。

正如你可以看到這個框架使用Twig,但是當我想用表單登錄人時,我向Model.php發送一個請求,在那裏啓動一個Session並設置$ _SESSION ['user'] ='約翰'例如。

問題是,我不知道如何檢查其他頁面是否已創建會話,甚至如何顯示頁面上的用戶名。

你能幫我嗎?

謝謝:)

+0

你有沒有試着用搜索引擎$ _session或使用本網站的搜索選項? –

回答

0

嘗試這樣:

session_start(); // start the session to have access to the session variables 

if(isset($_SESSION['user'])) { // check the existance of a variable with isset() 
    echo "User ".$_SESSION['user']." is logged on"; 
}