我正在使用一个$_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);
}
}
这会影响保存会话变量的路径吗?如果是这样,我该如何解决?
提前致谢...