Simple admin php code

Simple PHP Admin Panel (Free Download)

Welcome to a tutorial on how to create a simple PHP admin panel. Since you are reading this, I will assume that you are interested in “powering up” your existing project and want to build an administrative component to it. So here is a sharing of my own – All done in pure HTML, CSS, Javascript, and PHP. No third-party frameworks. Read on!

TABLE OF CONTENTS

PHP MYSQL ADMIN PANEL

All right, let us now get into the details of how to create a simple admin panel with PHP and MySQL.

PART 1) USER DATABASE

-- (A) USERS TABLE CREATE TABLE `users` ( `user_id` bigint(20) NOT NULL, `user_email` varchar(255) NOT NULL, `user_name` varchar(255) NOT NULL, `user_password` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `users` ADD PRIMARY KEY (`user_id`), ADD UNIQUE KEY `user_email` (`user_email`), ADD KEY `user_name` (`user_name`); ALTER TABLE `users` MODIFY `user_id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1; -- (B) DEFAULT USER -- EMAIL: JOY@DOE.COM | PASSWORD: 123456 INSERT INTO `users` (`user_id`, `user_email`, `user_name`, `user_password`) VALUES (1, 'joy@doe.com', 'Joy Doe', '$2y$10$vZJy7y4uqQQTRN3zdi2RE.5ZJJzGEEPnzEjFXm4nEOx023XQ2Qe..');
  • user_id Primary key and auto-increment.
  • user_email User email, unique to prevent duplicates.
  • user_name User name.
  • user_password The user’s password.
Читайте также:  Training certification in java

PART 2) PHP ADMIN LIBRARY

pdo = new PDO( "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=".DB_CHARSET, DB_USER, DB_PASSWORD, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); > // (B) DESTRUCTOR - CLOSE CONNECTION function __destruct () < if ($this->stmt !== null) < $this->stmt = null; > if ($this->pdo !== null) < $this->pdo = null; > > // (C) HELPER FUNCTION - RUN SQL QUERY function query ($sql, $data=null) : void < $this->stmt = $this->pdo->prepare($sql); $this->stmt->execute($data); > // (D) GET USER BY ID OR EMAIL function get ($id) < $this->query(sprintf("SELECT * FROM `users` WHERE `%s`=?", is_numeric($id) ? "user_id" : "user_email" ), [$id]); return $this->stmt->fetch(); > // (E) SAVE USER function save ($name, $email, $password, $id=null) < // (E1) SQL & DATA $sql = $id==null ? "INSERT INTO `users` (`user_name`, `user_email`, `user_password`) VALUES (. )" : "UPDATE `users` SET `user_name`=?, `user_email`=?, `user_password`=? WHERE `user_id`=?" ; $data = [$name, $email, password_hash($password, PASSWORD_DEFAULT)]; if ($id!=null) < $data[] = $id; >// (E2) RUN SQL $this->query($sql, $data); return true; > // (F) VERIFICATION function verify ($email, $password) < // (F1) GET USER $user = $this->get($email); $pass = is_array($user); // (F2) CHECK PASSWORD if ($pass) < $pass = password_verify($password, $user["user_password"]); >// (F3) REGISTER MEMBER INTO SESSION if ($pass) < foreach ($user as $k=>$v) < $_SESSION["admin"][$k] = $v; >unset($_SESSION["admin"]["user_password"]); > // (F4) RESULT if (!$pass) < $this->error = "Invalid email/password"; > return $pass; > > // (G) DATABASE SETTINGS - CHANGE TO YOUR OWN define("DB_HOST", "localhost"); define("DB_NAME", "test"); define("DB_CHARSET", "utf8mb4"); define("DB_USER", "root"); define("DB_PASSWORD", ""); // (H) START! session_start(); $_ADM = new Admin();
  • (A, B, H) When $_ADM = new Admin() is created, the constructor will connect to the database. The destructor closes the connection.
  • (C) query() A helper function to execute an SQL query.
  • (D to F) The actual admin functions.
    • get() Get user by ID or email.
    • save() Add or update a user.
    • verify() Verify the given email and password. Register the user into $_SESSION[«admin»] .

    PART 3) LOGIN PAGE

    verify($_POST["email"], $_POST["password"]); > // (C) REDIRECT IF SIGNED IN if (isset($_SESSION["admin"])) < header("Location: 5-protected.php"); exit(); >?> error!="") < echo "?> 

    ADMIN LOGIN

    • (D) A good old HTML login form.
    • (A & B) On submission, we use the library to process the login request.
    • (C) On successful login, we redirect the user to the “main admin page”; Any users who are already signed in will also be redirected.

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    This is a simple PHP, Jquery, ajax admin panel for small softwares and website panels. it uses google captcha. it is not depended on sql, but it keeps data in credential.php

    License

    supreen/php-admin-panel

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    This is a simple PHP, Jquery, ajax admin panel for small softwares and website panels. it uses google captcha. it is not depended on sql, but it keeps data in every file [After Update, all data is kept in one file named credential.php]

    It is designed for beginners.However, it does require sql

    APlease Use Your Google Captcha Sitekey and Secret [after update they are in one file named credential.php]

    Copy the Index.php file and create as many page as you want.

      UI improved
      background and Logo added
      Now you need to put Admin name, Password, Sitekey, SecretKey just in one file called Credential.php
      Get your google captcha sitekey and secret for your website from https://www.google.com/recaptcha/admin/create . make sure that it is «captcha v2» and «i am not robot» and put them in credential.php.
      Navbar can be updated via navbar.php too
      Replace logo.png with any logo of your choice
      Change the background image via \login\images\bg-01.jpg
      UI improved
      New Modern Navbar added
      Index.php preview updated in readme
      CSS, JS and other files were missing, they are added
      Instruction to get Captcha sitekey and secret key added
      SQL based Admin panel created in new repository
      nav bar was not showing properly. (bug fixed)
      Navbar is now fully functional and clickable
      add your codes in the resources folder to give life to your panel

    Here is the demo (SQL based)

    Consider buying me a coffee, if you loved my work.

    If you are still finding it hard, Hire me

    Image of Admin Panel

    Image of Index

    About

    This is a simple PHP, Jquery, ajax admin panel for small softwares and website panels. it uses google captcha. it is not depended on sql, but it keeps data in credential.php

    Источник

    Simple Company Website with an Admin Panel in PHP Free Source Code

    This is a Simple Company Website with an Admin Panel project in PHP Language. This web-based application generates a single-page company/business website. The website information is dynamics which means it has a feature where the company/business management/staff can modify the content, details, and other information in the system using without making any changes in the source code. The system has an Admin Panel where the system admin user will have a front-end to configure the information on the website.

    The IT services company you’re working with would require access to this panel to perform their day-to-day tasks.

    About The Simple Company Website Web App

    This project was developed using PHP, MySQL Database, HTML, CSS, Javascript (Ajax and jQuery), Bootstrap, AdminLTE Template, StartBootstrap Free Template (for the website UI), and some other libraries/plugins. The application is easy to use and easy to understand. It has a pleasant Admin Panel and Website user Interface also. This application also has one template for the website. If you wish to use other templates, just check the queries inside the index file of the source code to know and have an idea of how the data are being queried and displayed.

    Features

    Admin Side

    • Secure Login/Logout
    • Dashboard
    • Manage About Content
    • Manage Company/Business Services Providing
    • Manage Clients List
    • Manage Testimonies
    • Manage Contact Information
    • Manage Inquiries
    • Manage Website Other Information
    • Manage Account Details

    Website (Single Page only)

    • Display Company Banner
    • Display About Content
    • Display the Services of the Company/Business Providing
    • Display Previous/Current Clients
    • Display Testimonies
    • Contact Form for Inquiries
    • Display Contact Details
    • and Display some other information

    Источник

Оцените статью