我正在使用看起來並未保存的$_SESSION['loggedIn']= true
。 我在保存前使用session_start()
。我可以直接在後面回顯變量並進行設置,但是,只要我更改頁面,該變量就消失了。我也用session_start()
之前,我在其他頁面閱讀...
現在,我有一個.htaccess文件是這樣的:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?v=$1 [QSA,L]
確定..所以這是的index.php
@session_start();
define("x_app", "1");
define('X_BASE', dirname(__FILE__));
require_once X_BASE.'/config/config.php';
include "classes/browser.php";
$browser = new Browser();
$browser->setBrowserCookie();
$_SESSION['browser'] = $browser;
$_SESSION['language'] = "english";
//Getting View
$v = explode('/', $_GET['v']);
$view = $v[0];
After this I load the view..
In this case Login, which is loaded by a require function
defined('x_app') or die;
require('helper.php');
$email = $_POST['email'];
$password = $_POST['password'];
if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true){
//Redirect to my portfolio landing page
}
else{ //Not Logged In
//Process Form
if(isset($_POST['email']) && isset($_POST['password'])){
$xLogin = new X_Login();
if($xLogin->login($email, $password) == true){
echo 'User is logged In';
//@session_start() ---> should I put this here again? Don't think so...
// ! This is the variable that I can't save
$_SESSION['loggedIn'] = true;
// ! I have an echo here but if change the page, it gets lost
echo 'session->'.$_SESSION['loggedIn'];
}else{
echo 'User is not logged in';
}
}
//Error in Form
elseif(!isset($_POST['email']) || !isset($_POST['password'])){
$error = "Login Error";
include('views/default.php');
}
}
這是該Cookie功能
公共函數setBrowserCookie(){
if(empty($_COOKIE['verifyUser'])){
$ip = $_SERVER['REMOTE_ADDR'];
$ub = $this->getBrowser();
@setcookie("verifyUser", $ip.$ub, time()+31536000);
}
}
這是否會影響保存會話變量的路徑?如果是這樣,我該如何解決它?
在此先感謝...
是否設置了會話Cookie? – 2012-04-27 16:28:59
你能不能發佈你的測試代碼 – Ing 2012-04-27 16:45:22