2014-10-22 82 views
-1

喜每次IM刷新或點擊一個按鈕,刷新我的索引頁......這是我的主要頁面,會話死亡....這裏是一個簡單的代碼:PHP會話正在刷新爲什麼?

//session.class.php 
<?php 
session_start(); 

$_SESSION["EMAIL"] = ""; 

$_SESSION["LOGED"] = 0; 

?> 

//index.php 
<?php 
include_once ('session.class.php'); 
if (isset($_GET['login'])) {/// it a button submit in my form that use for login 
    $_SESSION["LOGED"] = 1; 
    include ("/module/Users/profile.php");// class that show profile if login an 
              // password is good 
    echo "session = ".$_SESSION["LOGED"]; 
} 
if ($_SESSION["LOGED"] == 0) { 
    echo userFormLogin();//show login 
    echo "<a href=index.php?content=register>Register</a>"; 
} 

?> 

TY每一個: D

+0

是什麼* 「會話死」 *實際上意味着什麼呢?當你包含'session.class.php'文件時,它會清除EMAIL屬性並將LOGED設置爲零嗎? – Phil 2014-10-22 00:26:40

+1

這意味着當頁面刷新....我的會話變量重置爲0 .....所以它沒有看到我作爲一個用戶登錄日誌 – user3718713 2014-10-22 00:29:11

+0

哼哼,我想這可能,但我不知道周圍的方式... 。如果它的概率我沒有idia如何設置會話變量爲零隻有一次,而不是覆蓋它... – user3718713 2014-10-22 00:30:26

回答

1

每次載入頁面時,您的EMAIL和LOGED會話變量都會重置。你不需要聲明它們,SESSIONS在你創建之前不存在。您基本上正在創建會話,但是當您加載頁面時,它會被設置爲0,然後再次請求登錄。

你應該使用:

if(isset($_SESSION['LOGED'])){ 
actions for logged in 
} 
else{ 
show login page 
}