我创建了一个用户页面。登录配置文件页面后,我想要包含用户名,邮件和密钥,但只显示用户名和电子邮件,但密钥不是。
用户页面代码:
<?php
session_start();
if (!isset($_SESSION['zalogowany']))
{
header('Location: ../logowanie');
exit();
}
$nick = $_SESSION['username'];
?>
<!DOCTYPE HTML>
<html lang="pl">
<head>
<title>NanoTech</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="../../css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="../../css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link rel="icon" type="image/png" href="/images/icon.png"/>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Profil Gracza</title>
</head>
<body>
<?php include '../../menu.php'; ?>
<div class="parallax-container">
<div class="parallax"><img src="../../files/tlo.png" alt="Unsplashed background img 1">
</div>
<div class="row">
<div class="z-depth-5 card-panel box-kontakt">
<?php
echo "<img src='https://mcapi.ca/avatar/$nick/100'>";
?>
<li class="divider"></li>
<div class="row">
<div class="col s12 black-text ">
<ul class="tabs black-text">
<li class="tab col s3"><a class='black-text active' href="#test1">Dane</a></li>
<li class="tab col s3"><a class="black-text" href="#test2">Secret Key</a></li>
<li class="tab col s3 disabled"><a href="#test3">Disabled Tab</a></li>
<li class="tab col s3"><a href="#test4">Test 4</a></li>
</ul>
</div>
<div id="test1" class="col s12">
<?php
echo "<p><b>Nick</b>: ".$_SESSION['username'];
echo "<p><b>E-mail</b>: ".$_SESSION['email'];
?>
</div>
<div id="test2" class="col s12"><?php echo $_SESSION['secret']; ?></div>
<div id="test3" class="col s12">Test 3</div>
<div id="test4" class="col s12">Test 4</div>
</div>
</div>
</div>
</div>
<?php require('../../footer.php')?>
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="../../js/materialize.js"></script>
<script src="../../js/init.js"></script>
</body>
</html>
会话获取代码:
<?php
session_start();
if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])))
{
header('Location: ../logowanie');
exit();
}
require_once "connect.php";
$polaczenie = @new mysqli($host, $db_user, $db_password, $db_name);
if ($polaczenie->connect_errno !== 0)
{
echo "Error: ".$polaczenie->connect_errno;
}
else
{
$login = $_POST['login'];
$haslo = $_POST['haslo'];
$login = htmlentities($login, ENT_QUOTES, "UTF-8");
if ($rezultat = $polaczenie->query(
sprintf("SELECT * FROM `authme` WHERE username='%s'",
mysqli_real_escape_string($polaczenie,$login))))
{
$ilu_userow = $rezultat->num_rows;
if($ilu_userow>0)
{
$wiersz = $rezultat->fetch_assoc();
if (password_verify($haslo, $wiersz['password']))
{
$_SESSION['zalogowany'] = true;
$_SESSION['id'] = $wiersz['id'];
$_SESSION['username'] = $wiersz['username'];
$_SESSION['email'] = $wiersz['email'];
$_SESSION['secret'] = $wiersz['secret'];
unset($_SESSION['blad']);
$rezultat->free_result();
header('Location: /');
}
else
{
$_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
header('Location: /user/logowanie');
}
} else {
$_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
header('Location: /user/logowanie');
}
}
$polaczenie->close();
}
?>