Home > Backend Development > PHP Tutorial > 怎样让这个blog.php页面显示登录的用户名呢?

怎样让这个blog.php页面显示登录的用户名呢?

WBOY
Release: 2016-06-23 13:16:52
Original
684 people have browsed it

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

blog.php
include "cookie.php";
?>

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

login.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 "登陆失败";
 }
 }
?>





用户名:
密码:




回复讨论(解决方案)

blog.php 中加入

<?php if(!(isset($_COOKIE['isLogin'])&&$_COOKIE['isLogin']==1)){ 	echo '您还没有登陆呢!请您登陆'; }else{    echo '您是登陆的,用户名是:'.$_COOKIE['username']; }?>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template