我开始在Windows Server 2008上使用php,并使用数据连接到MS SQL SERVER。过去我在apache和mysql上做过。但是现在我已经改变了,我的会话变量不再起作用了。只有一个会话变量存储在服务器上的会话文件中。虽然我在多个文件上有多个会话变量。存储的唯一行如下:
if (!isset($_SESSION["language"])){$_SESSION["language"] =
substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);}
在我的档案中:
语言| S:2: “NL”;
当我继续登录我的应用程序时,我存储了以下会话变量:
$result = sqlsrv_query($conn,$sql,$params,$options);
$numrows = sqlsrv_num_rows($result);
$row = sqlsrv_fetch_array($result);
if ($numrows > 0) {
$_SESSION['loggedin']= TRUE;
$_SESSION['username']= $row['username'];
$_SESSION['name']= $row['firstname'].' '.$row['lastname'];
$_SESSION['language']= $row['language'];
//if ($row['admin'] == 1){$_SESSION['admin']= TRUE;}
//if ($row['all_orders'] == 1){$_SESSION['allorders']= TRUE;}
//if ($row['validate'] == 1){$_SESSION['validate'] = TRUE;}
echo 'Welcome '.strtoupper(trim($_SESSION['name'])); }
else {
echo 'Login niet correct '.$username.' '.$password; };
但是在文件中我找不到这些会话变量。它们不存储在任何地方,因此我无法在其他页面上调用它们。任何人都有了主意。
答案 0 :(得分:1)
session_start();//session_start — Start new or resume existing session
$result = sqlsrv_query($conn,$sql,$params,$options);
$numrows = sqlsrv_num_rows($result);
$row = sqlsrv_fetch_array($result);
if ($numrows > 0) {
$_SESSION['loggedin']= TRUE;
$_SESSION['username']= $row['username'];
$_SESSION['name']= $row['firstname'].' '.$row['lastname'];
$_SESSION['language']= $row['language'];
//if ($row['admin'] == 1){$_SESSION['admin']= TRUE;}
//if ($row['all_orders'] == 1){$_SESSION['allorders']= TRUE;}
//if ($row['validate'] == 1){$_SESSION['validate'] = TRUE;}
echo 'Welcome '.strtoupper(trim($_SESSION['name'])); }
else {
echo 'Login niet correct '.$username.' '.$password; };
如果你得到if($ numrows> 0){return TRUE;}那么它必须是由于session_start();你无法存储会话价值。