RonKevinT.Manuela 0 Junior Poster in Training

So, my groupmate designed the look of our website...I was trying to integrate it with the other code....I decided to first do the login form....i dont know but I cant get it to work...-_-
1. lets start from the config.php:

<?php
ob_start();
session_start();
include('functions.php');

//database credentials
define('DBHOST','localhost');
define('DBUSER','root');
define('DBPASS','');
define('DBNAME','sics');

$db = new PDO("mysql:host=localhost; dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//set timezone
date_default_timezone_set('Europe/London');

//load classes as needed
function __autoload($class) {

   $class = strtolower($class);

   //if call from within assets adjust the path
   $classpath = 'classes/class.'.$class . '.php';
   if ( file_exists($classpath)) {
      require_once $classpath;
   }  

   //if call from within admin adjust the path
   $classpath = '../classes/class.'.$class . '.php';
   if ( file_exists($classpath)) {
      require_once $classpath;
   }

   //if call from within admin adjust the path
   $classpath = '../../classes/class.'.$class . '.php';
   if ( file_exists($classpath)) {
      require_once $classpath;
   }     

}

$user = new User($db); 

?>
  1. heres the class.user.php:

    <?php

    include('class.password.php');

    class User extends Password{

    private $db;
    
    function __construct($db){
        parent::__construct();
    
    
        $this->_db = $db;
    
    
    }
    
    public function is_logged_in(){
        if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){
            return true;
        }       
    }
    
    private function get_user_hash($id){    
    
        try {
    
            $stmt = $this->_db->prepare('SELECT password FROM members WHERE idNUMBER = :id');
            $stmt->execute(array('id' => $id));
    
            $row = $stmt->fetch();
            return $row['password'];
    
        } catch(PDOException $e) {
            echo '<p class="error">'.$e->getMessage().'</p>';
        }
    }
    
    
    public function login($id,$password){   
    
        $hashed = $this->get_user_hash($id);
    
        if($this->password_verify($password,$hashed) == 1){
    
            $_SESSION['loggedin'] = true;
            return true;
        }       
    }
    
    
    public function logout(){
        session_destroy();
    }
    

    }

    ?>

  2. Login.php:

    <?php include('../includes/config.php');
    //check if already logged in
    if( $user->is_logged_in() ){ header('Location: /users/MainPanel.php'); } ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="../img/logor2.png">

    <title>SICS | Log-in</title>
    
    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="../css/bootstrap.css">
    <link rel="stylesheet" href="../css/sticky-footer-navbar.css">
    <link rel="stylesheet" href="../css/bootflat.css">
    <link rel="stylesheet" href="../css/login.css">
    

    </head>

    <body>
    <!-- NAVIGATION -->
    <?php include_once("../includes/navbar.php"); ?>

    <!--CONTENT-->
    <div class="container">
      </br>
      <div class="col-md-4 col-md-offset-4 area">
        <form role="form" method="post">
          </br>
          </br>
          </br>
          </br>
          </br>
          <div class="form-group login-only">
            <i class="login-icon glyphicon glyphicon-user"></i>
            <input type="text" class="form-control"  placeholder="ID Number" name="idnumber">
          </div>
          <div class="form-group login-only">
            <i class="login-icon glyphicon glyphicon-asterisk"></i>
            <input type="password" class="form-control" placeholder="Password" name="password">
          </div>
          <button type="submit" class="btn btn-primary btn-lg col-md-offset" name="submit">Log-in</button>
          <?php include_once('../includes/submitlogin.php'); ?>
        </form>
      </div>
    </div>
    
    
    <!-- FOOTER -->
     <?php include_once('../includes/footer.php');?>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    
    <!-- Bootflat js files -->
    <!-- Bootflat's JS files.-->
    <script src="../js/icheck.min.js"></script>
    <script src="../js/jquery.fs.selecter.min.js"></script>
    <script src="../js/jquery.fs.stepper.min.js"></script>
    

    </body>

    </html>

  3. SubmitLogin:

    <?php

    //process login form if submitted
    if(isset($_POST['submit'])){

    $id = $_POST['idnumber'];
    $password = $_POST['password'];
    
    if($user->login($id,$password)){ 
    
      //logged in return to MainPanel page
      $_SESSION['idnumber']=$id;
      header('Location: ../users/MainPanel.php');
      exit;
    
    
    } else {
      $message = '<p class="error">Wrong ID Number or Password</p>';
    
    }
    

    }//end if submit

    if(isset($message)){ echo $message; }
    ?>

  4. Where the admin will be rediected when logged in:

    <?php require_once('../includes/config.php');
    if( !$user->is_logged_in() ){ header('Location: ../users/login.php'); } ?>
    ?>
    <!DOCTYPE html>
    <html lang="en">

    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../img/logor2.png">

    <title>SICS | Admin</title>
    
    <!-- Bootstrap core CSS -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <link href="../css/simple-sidebar.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/bootflat.css">
    <style type="text/css">
        body {
            background-color: #FFCCFF;
        }
        .area {
            border: none;
            border-radius: 4px;
            background-color: white;
            -webkit-box-shadow: 0 0px 0px rgba(0, 0, 0, .2);
                -moz-box-shadow: 0 0px 0px rgba(0, 0, 0, .2);
                    box-shadow: 0 0px 0px rgba(0, 0, 0, .2);
            padding: 8px;
        }
        .content-area {
            border: solid 2px #FFCCFF;
            border-radius: 4px;
            background-color: none;
            -webkit-box-shadow: 0 0px 0px rgba(0, 0, 0, .2);
                -moz-box-shadow: 0 0px 0px rgba(0, 0, 0, .2);
                    box-shadow: 0 0px 0px rgba(0, 0, 0, .2);
            padding: 8px;
        }
        .breadcrumb {
            background-color: white;
        }
    </style>
    

    </head>

    <body>

    <div id="wrapper">
    
        <!-- Sidebar -->
        <div id="sidebar-wrapper">
            <ul class="sidebar-nav">
               <?php
               $query = 'SELECT roleID from members where idNUMBER="'.$_SESSION['idnumber'].'"';
                try {
                        $pdoStatement = $db->query($query);
                }
                    catch (PDOException $exception) {
                        // the query failed and debugging is enabled
                        echo "<p>There was an error in query: $query</p>";
                        echo $exception->getMessage();
                        $pdoStatement = false;
                    }
                    if ($pdoStatement) {
                        // the query was successful
                        // get the result (if any)
                        // fetchObject returns FALSE if there is no record
                    if ($recordObj = $pdoStatement->fetchObject()) {
                        $role=$recordObj->roleID;       
                        if ($role == 1) {
                            echo "<li class='text-center'><a href='#'><h4>ADMIN PANEL</h4></a></li></br>
                            <li class='text-center'><a href='adminpanel.html'><img src='../img/mainpanel.png'></a></li></br>
                            <li class='text-center'><a href='categories.html'><img src='../img/categories.png'></a></li></br>
                            <li class='text-center'><a href='users.html'><img src='../img/users.png'></a></li></br>
                            <li class='text-center'><a href='index.html'><img src='../img/web.png'></a></li></br>
                            <li class='text-center'><a href='#'><img src='../img/photogallery.png'></a></li></br>
                            <li class='text-center'><a href='logout.php'><img src='../img/logout.png'></a></li>";
                        }
                        elseif ($role == 2) {
                            echo "<h1>Welcome SICS Faculty!</h1>
                            <ul id='adminmenu'>
                            <li><a href='index.php'>Main Panel</a></li>
                            <li><a href='categories.php'>Categories</a></li>
                            <li><a href='/CapstoneProject/home.php'>Department Website</a></li>
                            <li><a href='logout.php'>Logout</a></li>
                            </ul>
                            <div class='clear'></div>
                            <hr />";
                        }
                        elseif ($role == 3) {
                        header('Location: /CapstoneProject/home.php');
                   }    
    
                }
            }
    

    $adminpanel=$role;
    $_SESSION['adminpanel']=$adminpanel;

    ?>

            </ul>
        </div>
    
        <!-- Page content -->
        <div id="page-content-wrapper">
    
            <div class="page-content inset">
                <div id="content" class="container">
                    <div class="row">
                        <div class="col-md-11">
                            <ol class="breadcrumb breadcrumb-arrow">
                                <li class="active"><a href="#">Main Panel</a></li>
                            </ol>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-11 area">
                            <div class="col-md-6 content-area">
                                <h4 class="text-center">POSTS</h4>
                            </div>
                            <div class="col-md-2 col-md-offset-1 content-area">
                                <h4 class="text-center">DATE</h4>
                            </div>
                            <div class="col-md-2 col-md-offset-1 content-area">
                                <h4 class="text-center">ACTION</h4>
                            </div>
                        </div>
                    </div>
    
                    <div class="row">
                        <div class="col-md-11 area">
                            <div class="col-md-6 content-area">
                                <p class="text-center">Post Title 1</p>
                                <p class="text-center">Post Title 1</p>
                                <p class="text-center">Post Title 1</p>
                                <p class="text-center">Post Title 1</p>
                                <p class="text-center">Post Title 1</p>
                                <p class="text-center">Post Title 1</p>
                                <p class="text-center">Post Title 1</p>
                            </div>
                            <div class="col-md-2 col-md-offset-1 content-area">
                                <p class="text-center">ddth mmm yyyy</p>
                                <p class="text-center">ddth mmm yyyy</p>
                                <p class="text-center">ddth mmm yyyy</p>
                                <p class="text-center">ddth mmm yyyy</p>
                                <p class="text-center">ddth mmm yyyy</p>
                                <p class="text-center">ddth mmm yyyy</p>
                                <p class="text-center">ddth mmm yyyy</p>
                            </div>
                            <div class="col-md-2 col-md-offset-1 content-area">
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                                <p class="text-center"><a href="edit-post.html">Edit</a> | <a href="">Delete</a></p>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2">
                            </br>
                            </br>
                            <a href="add-post.html"><button type="button" class="btn btn-primary btn-lg col-md-offset-1">+ New Post</button></a>
                        </div>
                    </div>
                </div>
    
                </div><!-- content -->
    
            </div>
    
    
        </div><!--page-content-wrapper-->
    
    </div>
    
    <!-- JavaScript -->
    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/icheck.min.js"></script>
    <script src="js/jquery.fs.selecter.min.js"></script>
    <script src="js/jquery.fs.stepper.min.js"></script>
    
    <!-- Custom JavaScript for the Menu Toggle -->
    <script>
    $("#menu-toggle").click(function(e) {
        e.preventDefault();
        $("#wrapper").toggleClass("active");
    });
    </script>
    

    </body>
    </html>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.