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

WBOY
發布: 2016-06-06 20:18:41
原創
839 人瀏覽過

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>
登入後複製
相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板