PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

在一个新的页面怎么获取已经登陆的用户名呢?

原创
2016-06-06 20:18:26 714浏览

直接这样$_COOKIE['username'] 不能打印出来登陆的用户名啊 我想用这个用户名怎么办呢?

登录页

prepare("select id,username,password from user where username=? and password=?");
 $stmt->execute(array($_POST['username'],($_POST['password'])));
 if($stmt->rowCount()>0){
 list($id,$username)=$stmt->fetch(PDO::FETCH_NUM);
   $time=time()+24*60*60;
   setCookie("uid",$id,$time,"//m.sbmmt.com/m/");
   setCookie("username",$username,$time,"//m.sbmmt.com/m/");
   setCookie("isLogin",1,$time,"//m.sbmmt.com/m/");
   echo '';
 }
 else{
     echo "登陆失败";
 }
}
?>




用户名: 密码:

回复内容:

直接这样$_COOKIE['username'] 不能打印出来登陆的用户名啊 我想用这个用户名怎么办呢?

登录页

prepare("select id,username,password from user where username=? and password=?");
 $stmt->execute(array($_POST['username'],($_POST['password'])));
 if($stmt->rowCount()>0){
 list($id,$username)=$stmt->fetch(PDO::FETCH_NUM);
   $time=time()+24*60*60;
   setCookie("uid",$id,$time,"//m.sbmmt.com/m/");
   setCookie("username",$username,$time,"//m.sbmmt.com/m/");
   setCookie("isLogin",1,$time,"//m.sbmmt.com/m/");
   echo '';
 }
 else{
     echo "登陆失败";
 }
}
?>




用户名: 密码:

你得先在登录成功的时候写一下COOKIE,写完了再访问新的页面,你的php代码才能读到它

没人啊。。。。。。。。。。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。