简体   繁体   English

通过php session的用户管理系统

[英]User management system through php session

Login.php登录.php

 <?php

    session_start();
    require("Register.php");    
    if(isset($_POST['loginButton'])){

        try {

            $email = $_POST['email'];
            $password = $_POST['password'];

            $query = $conn->prepare("SELECT * FROM Users WHERE Email = '$email' AND password = '$password'");
            $query->execute();

            if($query->rowCount() > 0 ) {
                    $_SESSION['user'] = $email;
                    header("location: ../html/myAccount.html");
            }
            else {
                echo "Email not found!";
            }
        }
        catch (PDOException $e){
                echo $e->getMessage();
        }
    }
?>  

HTML page HTML页面

    <?php
    session_start();
    echo $_SESSION['user'];
    ?>


    <!DOCTYPE html>
    <HTML>
    <HEAD>
        <title>BMA.WALLET</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <link rel="stylesheet" type="text/css" href="../css/page-style.css">
        <link rel="stylesheet" type="text/css" href="../css/account-style.css">

        <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css'>
        <link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,100italic,300italic,400italic,500,500italic,700,700italic,900,900italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>

        <link rel="shortcut icon" href="../img/wallet.png"/>
    </HEAD>

    <BODY> 
        <div id="wrapper">
        <div id="HEADER">
            <h1><span>BMA.</span>WALLET</h1>
            <div class="motto">Cu noi știi unde ți-au zburat banii!</div>
            <div class="main-menu">
                <ul>
                    <li><a href="Facilities.html"><img src="../img/facilities.png" width="40" alt="logout icon" title="Facilități"></a></li>
                    <li><a href="myAccount.html"><img src="../img/report.png" width="40" alt="logout icon" title="Rapoartele tale"></a></li>
                    <li><a href="groupPage.html"><img src="../img/group.png" width="40" alt="logout icon" title="Grupurile tale"></a></li>
                    <li><a href="Settings.html"><img src="../img/settings.png" width="40" alt="settings icon" title="Setările tale"></a></li>
                    <li><a href="#"><img src="../img/iconLogout.png" width="40" alt="logout icon" title="Deconectează-te!"></a></li>
                </ul>

            </div>
        </div>

        <div class="center" id="CONTENT">
            <div class="personal-reports">
                <h1>Contul personal - rapoarte</h1>

                <h2>Statistică periodică: Venituri și Cheltuieli </h2>

I am building for my project a user management system and I want to show after log in the user's profile.我正在为我的项目构建一个用户管理系统,我想在登录用户的个人资料后显示。 After I press login I should be redirected to the html page .按登录后,我应该被重定向到html page This works but I don't know how to print in the HTML page the value of $_SESSION , it doesn't matter where or how I just want to test it so I can see if it works and I get the $SESSION value .这有效,但我不知道如何在HTML页面中打印$_SESSION的值,我只想测试它的位置或方式无关紧要,以便我可以查看它是否有效并获得$SESSION value I found no solution to this so if you can help me I would really appreciate.我没有找到解决方案,所以如果你能帮助我,我将不胜感激。

You have stored your email in the session variable:您已将电子邮件存储在会话变量中:

$_SESSION['user'] = $email;

So, in your other HTML page, you simply need to echo this:因此,在您的其他 HTML 页面中,您只需要回显:

// myAccount.html // 我的账户.html

<?php echo "Logged in user: ".$_SESSION['user']; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM