>  기사  >  백엔드 개발  >  我想让这个blog.php页面把登陆的用户名打印出来应该怎么写呢?

我想让这个blog.php页面把登陆的用户名打印出来应该怎么写呢?

WBOY
WBOY원래의
2016-06-06 20:18:41842검색

blog.php

<code> <?php include "cookie.php";
    ?></code>

cookie页面

<code><?php if(!(isset($_COOKIE['isLogin'])&&$_COOKIE['isLogin']==1)){
     echo '您还没有登陆呢!请您登陆';
 }else{
    echo '您是登陆的';
 }
?>
</code>

login.php

<code><?php $pdo=new PDO("mysql:host=localhost;dbname=t1;","root","");
 if(isset($_POST['submit'])){
 $stmt=$pdo->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,"/");
   setCookie("username",$username,$time,"/");
   setCookie("isLogin",1,$time,"/");
   echo '<script>location="blog.php"</script>';
 }
 else{
     echo "登陆失败";
 }
 }
?>




<form action="login.php" method="post">
用户名:<input type="text" name="username">
密码:<input type="text" name="password">
<button type="submit" name="submit">登录</button>
</form>

</code>

回复内容:

blog.php

<code> <?php include "cookie.php";
    ?></code>

cookie页面

<code><?php if(!(isset($_COOKIE['isLogin'])&&$_COOKIE['isLogin']==1)){
     echo '您还没有登陆呢!请您登陆';
 }else{
    echo '您是登陆的';
 }
?>
</code>

login.php

<code><?php $pdo=new PDO("mysql:host=localhost;dbname=t1;","root","");
 if(isset($_POST['submit'])){
 $stmt=$pdo->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,"/");
   setCookie("username",$username,$time,"/");
   setCookie("isLogin",1,$time,"/");
   echo '<script>location="blog.php"</script>';
 }
 else{
     echo "登陆失败";
 }
 }
?>




<form action="login.php" method="post">
用户名:<input type="text" name="username">
密码:<input type="text" name="password">
<button type="submit" name="submit">登录</button>
</form>

</code>

setCookie("username",$username,$time,"/");

<code>echo $username;//打印用户名</code>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.