1

Login.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

    <?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. 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. I found no solution to this so if you can help me I would really appreciate.

Senjuti Mahapatra
  • 2,570
  • 4
  • 27
  • 38
  • the html page code is just a sample, it has no problems. – The Deepest Sleep May 26 '16 at 09:34
  • 1
    `"SELECT * FROM Users WHERE Email = '$email' AND password = '$password'"` --- Please don't deploy this code anywhere in the real world! You're storing passwords in plain text, and are vulnerable to SQL injection attacks. A malicious user could easily steal everyone's passwords. – Tom Lord May 26 '16 at 09:42
  • It will be modified by the time I finish the project. – The Deepest Sleep May 26 '16 at 09:51

1 Answers1

1

You have stored your email in the session variable:

$_SESSION['user'] = $email;

So, in your other HTML page, you simply need to echo this:

// myAccount.html

<?php echo "Logged in user: ".$_SESSION['user']; ?>
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32