-1
4

3 回答 3

2
于 2012-12-05T06:00:31.340 回答
2

检查是否$_SESSION's存储任何值..

我给你举个例子:

  <?php
 //This will start a session
 session_start();

 if(isset($_SESSION['username']))
 {
     $username = $_SESSION['username'];
}else{
  $username = null;
}
var_dump($username);

// Would return NULL. SESSION IS NOT SET.
// if I add $_SESSION['username'] = "Phorce" session set, will return phorce.
?> 

或者:var_dump($_SESSION['username']);

希望这会有所帮助:) 可能$_SESSION['username']是没有注册。

于 2012-12-05T06:01:15.787 回答
1

请在使用前检查会话变量是否已分配值。

<?php
//This will start a session
session_start();

$username ="";
$password ="";
if(isset($_SESSION['username']))
$username = $_SESSION['username'];

if(isset($_SESSION['password ']))
$password = $_SESSION['password'];

//Check do we have username and password
if(!$username && !$password){
echo "Welcome Guest! <br> <a href=login.php>Login</a> | <a href=register.php>Register</a>";
}else{
echo "Welcome ".$username." (<a href=logout.php>Logout</a>)";
}
?> 
于 2012-12-05T06:06:05.110 回答