嘿伙计们,我不知道为什么我不能echo $_SESSION['name']
在 index.php 上说
Undefined index: name in C:\xampp\htdocs\STT\index.php on line 52
You are logged as
PHP代码:
$username = (isset($_POST['username'])) ? trim($_POST['username']) : '' ;
$password = (isset($_POST['password'])) ? trim($_POST['password']) : '' ;
if (isset($_POST['submit']) && ($_POST['submit'] = 'Login')) {
$query='SELECT * FROM user_info WHERE username = "'. $username .'" AND password = PASSWORD("'. $password .'") ';
$result = mysql_query($query) or die(mysql_error()) ;
$count = mysql_num_rows($result) ;
if ( $count == 1 ) {
$_SESSION['logged'] = 1 ;
$_SESSION['name'] = $_POST['username'] ;
echo 'successfully logged.' ;
header ('Refresh : 5 ; URL = index.php') ;
}
else {
echo 'Invalid username or password' ;
$_SESSION['logged'] = 0 ;
}
}
和 index.php
<?php
if ( $_SESSION['logged'] = 1) {
echo 'You are logged as' . $_SESSION['name'] ;
}
else {
echo 'WTF';
}
?>