require_once '../include.php';
try{
//1.通过dsn链接数据库,可用config
$dsn='mysql:host=localhost;dbname=cyotel';
//2.uri链接
//$dsn='uri:file://D:\...\dsn.txt';
//3.通过配置文件php.ini
$username='root';
$password='root';
$pdo=new PDO($dsn,$username,$password);
//打印连接结果
}catch(PDOException $e){
echo $e->getMessage();
}
$username=$_POST['username'];
$username=addslashes($username);
$password=md5($_POST['password']);
$verify=$_POST['verify'];
$verify1=$_SESSION['verify'];
$autoFlag=$_POST['autoFlag'];
if($verify==$verify1){
$sql="select * from c_admin where username='{$username}' and password='{$password}'";
$result=$pdo->query($sql);
$row=$result->fetchAll(PDO::FETCH_ASSOC);
if($row){
//如果选了一周内自动登陆
if($autoFlag){
setcookie("adminId",$row['id'],time()+7*24*3600);
setcookie("adminName",$row['username'],time()+7*24*3600);
}
$_SESSION["adminName"]=$row['username'];
$_SESSION["adminId"]=$row['id'];
// alertMes("登陆成功","index.php");
print_r($_SESSION);
var_dump($_SESSION);
var_dump($row);
}else{
// alertMes("登陆失败,重新登陆","login.php");
}
}else{
// alertMes("验证码错误","login.php");
}
array (size=3)
'verify' => string '7041' (length=4)
'adminName' => null
'adminId' => null打印的结果如下,从数据库中取出来值了,但是写入session失败,也没有报错,都是notice提醒;session也开启了,路径是c:wamp/tmp
array (size=1)
0 =>
array (size=4)
'id' => string '2' (length=1)
'username' => string 'admin' (length=5)
'password' => string '21232f297a57a5a743894a0e4a801fc3' (length=32)
'tel' => string '13760410581' (length=11)
求大神解答一下,感激不尽~