User Account Registration (Signup)

This commit is contained in:
Underemployed 2023-01-15 07:52:14 +06:30
parent 73d97f9f1d
commit cde36783e4
11 changed files with 51 additions and 57 deletions

View file

@ -1,5 +1,6 @@
<?php <?php
define("ROOT_URL", "https://localhost/blog/"); session_start();
define("ROOT_URL", "http://localhost/blog/");
define('DB_HOST', 'localhost'); define('DB_HOST', 'localhost');
define('DB_USER', 'underemployed'); define('DB_USER', 'underemployed');
define('DB_PASS', 'admin1234'); define('DB_PASS', 'admin1234');

View file

@ -24,7 +24,7 @@ include "partials/header.php";
<h5>Manage Posts</h5> <h5>Manage Posts</h5>
</a> </a>
</li> </li>
<?php if(isset($_SESSION['user_is_admin'])) : ?>
<li> <li>
<a href="<?= ROOT_URL ?>admin/add-user.php"> <a href="<?= ROOT_URL ?>admin/add-user.php">
<i class="uil uil-user-plus"></i> <i class="uil uil-user-plus"></i>
@ -50,6 +50,7 @@ include "partials/header.php";
<h5>Manage Categories</h5> <h5>Manage Categories</h5>
</a> </a>
</li> </li>
<?php endif ?>
</ul> </ul>
</aside> </aside>
<main> <main>

View file

@ -20,10 +20,11 @@ include "partials/header.php";
<li> <li>
<a href="<?= ROOT_URL ?>admin/index.php"> <a href="<?= ROOT_URL ?>admin/index.php">
<i class="uil uil-postcard"></i> <h5>Manage Posts</h5> <i class="uil uil-postcard"></i>
<h5>Manage Posts</h5>
</a> </a>
</li> </li>
<?php if(isset($_SESSION['user_is_admin'])) : ?>
<li> <li>
<a href="<?= ROOT_URL ?>admin/add-user.php"> <a href="<?= ROOT_URL ?>admin/add-user.php">
<i class="uil uil-user-plus"></i> <i class="uil uil-user-plus"></i>
@ -49,6 +50,7 @@ include "partials/header.php";
<h5>Manage Categories</h5> <h5>Manage Categories</h5>
</a> </a>
</li> </li>
<?php endif ?>
</ul> </ul>
</aside> </aside>
<main> <main>

View file

@ -20,10 +20,11 @@ include "partials/header.php";
<li> <li>
<a href="<?= ROOT_URL ?>admin/index.php"> <a href="<?= ROOT_URL ?>admin/index.php">
<i class="uil uil-postcard"></i> <h5>Manage Posts</h5> <i class="uil uil-postcard"></i>
<h5>Manage Posts</h5>
</a> </a>
</li> </li>
<?php if(isset($_SESSION['user_is_admin'])) : ?>
<li> <li>
<a href="<?= ROOT_URL ?>admin/add-user.php"> <a href="<?= ROOT_URL ?>admin/add-user.php">
<i class="uil uil-user-plus"></i> <i class="uil uil-user-plus"></i>
@ -49,6 +50,8 @@ include "partials/header.php";
<h5>Manage Categories</h5> <h5>Manage Categories</h5>
</a> </a>
</li> </li>
<?php endif ?>
</ul> </ul>
</aside> </aside>
<main> <main>

View file

@ -1,48 +1,10 @@
<?php <?php
require 'config/database.php'; require '../partials/header.php';
// check login status
if(!isset($_SESSION['user-id'])) {
header('location: ' . ROOT_URL . 'signin.php');
die();
}
?> ?>
<!DOCTYPE HTML>
<php 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.0">
<title>php & mysql blog app with admin panel</title>
<!-- CUSTOM STYLESHEET -->
<link rel="stylesheet" href="<?= ROOT_URL ?>css/style.css">
<!-- ICONSCOUT CDN -->
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.0/css/line.css">
<!-- GOOGLE FONT(MONTSERATE) -->
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,800;1,700&display=swap" rel="stylesheet">
</head>
<body>
<nav>
<div class="container nav__container">
<a href="<?= ROOT_URL ?>index.php" class="nav__logo">UNDEREMPLOYED</a>
<ul class="nav__items">
<li><a href="<?= ROOT_URL ?>blog.php">Blog</a></li>
<li><a href="<?= ROOT_URL ?>about.php">About</a></li>
<li><a href="<?= ROOT_URL ?>services.php">Services</a></li>
<li><a href="<?= ROOT_URL ?>contact.php">Contact</a></li>
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li>
<li class="nav__profile">
<div class="avatar">
<img src="./images/avatar1.jpg">
</div>
<ul>
<li><a href="<?= ROOT_URL ?>/admin/index.php">Dashboard</a></li>
<li><a href="<?= ROOT_URL ?>logout.php">Logout</a></li>
</ul>
</li>
</ul>
<button id="open__nav-btn"><i class="uil uil-bars"></i></button>
<button id="close__nav-btn"><i class="uil uil-multiply"></i></button>
</div>
</nav>
<!-- ======================== END OF NAV ======================== -->

View file

@ -1,5 +1,6 @@
<?php <?php
define("ROOT_URL", "https://localhost/blog/"); session_start();
define("ROOT_URL", "http://localhost/blog/");
define('DB_HOST', 'localhost'); define('DB_HOST', 'localhost');
define('DB_USER', 'underemployed'); define('DB_USER', 'underemployed');
define('DB_PASS', 'admin1234'); define('DB_PASS', 'admin1234');

8
logout.php Normal file
View file

@ -0,0 +1,8 @@
<?php
require 'config/constants.php';
//destroy all sessions and redirect user to login page
session_destroy();
header('location: ' . ROOT_URL);
die;
?>

View file

@ -1,6 +1,12 @@
<?php <?php
require 'config/database.php'; require 'config/database.php';
if(isset($_SESSION['user-id'])) {
$id = filter_var($_SESSION['user-id'], FILTER_SANITIZE_NUMBER_INT);
$query = "SELECT avatar FROM users WHERE id='$id'";
$result = mysqli_query($connection, $query);
$avatar = mysqli_fetch_assoc($result);
}
?> ?>
@ -28,16 +34,20 @@ require 'config/database.php';
<li><a href="<?= ROOT_URL ?>about.php">About</a></li> <li><a href="<?= ROOT_URL ?>about.php">About</a></li>
<li><a href="<?= ROOT_URL ?>services.php">Services</a></li> <li><a href="<?= ROOT_URL ?>services.php">Services</a></li>
<li><a href="<?= ROOT_URL ?>contact.php">Contact</a></li> <li><a href="<?= ROOT_URL ?>contact.php">Contact</a></li>
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li> <?php if(isset($_SESSION['user-id'])) : ?>
<!--<li class="nav__profile">
<li class="nav__profile">
<div class="avatar"> <div class="avatar">
<img src="./images/avatar1.jpg"> <img src="<?= ROOT_URL . 'images/' . $avatar['avatar'] ?>">
</div> </div>
<ul> <ul>
<li><a href="<?= ROOT_URL ?>/admin/index.php">Dashboard</a></li> <li><a href="<?= ROOT_URL ?>/admin/index.php">Dashboard</a></li>
<li><a href="<?= ROOT_URL ?>logout.php">Logout</a></li> <li><a href="<?= ROOT_URL ?>logout.php">Logout</a></li>
</ul> </ul>
</li>--> </li>
<?php else : ?>
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li>
<?php endif ?>
</ul> </ul>
<button id="open__nav-btn"><i class="uil uil-bars"></i></button> <button id="open__nav-btn"><i class="uil uil-bars"></i></button>

View file

@ -4,17 +4,22 @@ require "config/database.php";
session_start(); session_start();
if(isset($_POST['submit'])){ if(isset($_POST['submit'])){
// getting input
$username_email = filter_var($_POST['username_email'] , FILTER_SANITIZE_FULL_SPECIAL_CHARS); $username_email = filter_var($_POST['username_email'] , FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$password = filter_var(($_POST['password']), FILTER_SANITIZE_FULL_SPECIAL_CHARS); $password = filter_var(($_POST['password']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if(!$username_email){ if(!$username_email){
$_SESSION['signin'] = 'Username or Email is Inccorrect'; $_SESSION['signin'] = 'Username or Email is Inccorrect';
} }
elseif(!$password){ elseif(!$password){
$_SESSION['signin'] = 'Password required'; $_SESSION['signin'] = 'Password required';
}else{ }else{
// fetch user from database // fetch user from database
$fetch_user_query = "SELECT * FROM users WHERE username = '$username_email' OR email = '$username_email'"; $fetch_user_query = "SELECT * FROM users WHERE username = '$username_email' OR email = '$username_email'";
$fetch_user_result = mysqli_query($connection, $fetch_user_query); $fetch_user_result = mysqli_query($connection, $fetch_user_query);
if(mysqli_num_rows($fetch_user_result) == 1){ if(mysqli_num_rows($fetch_user_result) == 1){
//convert the record into assoc array //convert the record into assoc array
$user_record=mysqli_fetch_assoc($fetch_user_result); $user_record=mysqli_fetch_assoc($fetch_user_result);
@ -22,12 +27,14 @@ if(isset($_POST['submit'])){
// compare form password with database password // compare form password with database password
if(password_verify($password,$db_password)){ if(password_verify($password,$db_password)){
// set session for access control // set session for access control
$_SESSION['user-id'] = $user_record['id']; $_SESSION['user-id'] = $user_record['id'];
//set session if user is admin //set session if user is admin
if($user_record['is_admin']==1){ if($user_record['is_admin']==1){
$_SESSION['user_is_admin'] == true; $_SESSION['user_is_admin'] == true;
} }
//log in user //log in user
header('location: ' . ROOT_URL . 'admin/'); header('location: ' . ROOT_URL . 'admin/');

View file

@ -1,5 +1,4 @@
<?php <?php
session_start();
include 'config/constants.php'; include 'config/constants.php';
$username_email = $_SESSION['signin-data']['username_email'] ??null ; $username_email = $_SESSION['signin-data']['username_email'] ??null ;