[英]How to display data from currently logged in user
I'm newbie in php coding.我是 php 编码的新手。 Just start it a few weeks ago.
几周前就开始吧。 I am making login, register and profile pages.
我正在制作登录、注册和个人资料页面。 I have a problem to display username that currently logged in. I tried all reference or tutorial and other forums.
我在显示当前登录的用户名时遇到问题。我尝试了所有参考或教程以及其他论坛。 but still not working.
但仍然无法正常工作。 Someone, please help me to solve.
有人请帮我解决。
Here is my auth.php这是我的auth.php
<?php
include ("config.php");
session_start();
if(!isset($_SESSION["user"])) header("Location: login.php");
?>
and the login.php和login.php
<?php
require_once("config.php");
if(isset($_POST['login'])){
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
$sql = "SELECT * FROM users WHERE username=:username OR email=:email";
$stmt = $db->prepare($sql);
$params = array(
":username" => $username,
":email" => $username
);
$stmt->execute($params);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Registered
if($user){
// verifikasi password
if(password_verify($password, $user["password"])){
// Make Session
session_start();
$_SESSION["user"] = $user;
//success and redirect
header("Location: index.php");
}
}
}
?>
<!DoctypeHTML>
<html>
<head>
</head>
<body>
</body>
</html>
Thank you谢谢
[PS = Sorry for my english] [PS = 对不起我的英语]
In index.php
, write these lines.在
index.php
,写下这些行。
<?php
if(isset($_SESSION['user'])){
echo $_SESSION['user']->fieldName; // here you need to retrieve fields
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.