banner



How To Create Unique Url For Each Of My Sites Registered Users With Php

In this article, we will encounter how we tin can create a login page for admin, connected with the database, or whose information to log in to the page is already stored in our database.

Follow the steps to create an admin login folio using PHP:

Arroyo: Make sure you take XAMPP or WAMP installed on your windows machine. In case you're using Linux OS then install the LAMP server. In this commodity, nosotros volition exist using the XAMPP server.

1. Create Database: Showtime, we will create a database named 'geeksforgeeks' (you can requite any name to your database). You tin also use your existing database or create a new one.

create database "geeksforgeeks"

ii. Create Tabular array: Create a tabular array named 'adminlogin' with iii columns to store the information.

create table "adminlogin"

3. Create Table Construction: The table "adminlogin" contains 3 fields.

  • id – chief key – automobile increment
  • username – varchar(100)
  • countersign – varchar(100)

The datatype for username and password is varchar. The size can be altered as per the requirement. However, 100 is sufficient, and the datatype for "id" is int and information technology is a master fundamental.
A master key likewise called a chief keyword is a key in a relational database that is unique for each record. It is a unique identifier, such as a driver'southward license number, phone number (including area code), or vehicle identification number (VIN).
Your table structure should look like this.

table construction

Or copy and paste the following code into the SQL console of your PHPMyAdmin.

DROP TABLE IF EXISTS `adminlogin`; CREATE TABLE IF Not EXISTS `adminlogin` (   `id` int(11) NOT Zip AUTO_INCREMENT,   `username` varchar(100) NOT NULL,   `password` varchar(100) NOT Nothing,   Primary KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

To do this from SQL Console refer to the following screenshot.

create a table from SQL panel

iv. Insert admin login information: Here, nosotros are inserting 2 records in our tabular array. You can add as many equally you want.

inserting records

Or re-create and paste the following code to insert records into the SQL console.

INSERT INTO `adminlogin` (`id`, `username`, `password`) VALUES (NULL, 'admin', 'admin'), (Null, 'admin2', 'admin2');

After inserting the values, the table will look similar this.

tabular array records

v. Create a folder that includes the following files: The folder should be in "C:\xampp\htdocs\" (or where your XAMPP is installed). For the WAMP server, it should exist in "C:\wamp64\www\" and on Linux "/opt/lampp/htdocs".

  • Filename: index.php

HTML

<!DOCTYPE html>

< html lang = "en" >

< head >

< meta charset = "UTF-8" >

< link rel = "stylesheet" href =

< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >

< meta http-equiv = "X-UA-Uniform" content = "ie=edge" >

< link rel = "stylesheet" href = "login.css" >

< championship >Login Page</ title >

</ head >

< body >

< class action = "validate.php" method = "post" >

< div grade = "login-box" >

< h1 >Login</ h1 >

< div class = "textbox" >

< i form = "fa fa-user" aria-hidden = "truthful" ></ i >

< input blazon = "text" placeholder = "Username"

name = "username" value = "" >

</ div >

< div class = "textbox" >

< i form = "fa fa-lock" aria-hidden = "true" ></ i >

< input type = "countersign" placeholder = "Countersign"

name = "password" value = "" >

</ div >

< input class = "push button" type = "submit"

proper name = "login" value = "Sign In" >

</ div >

</ form >

</ torso >

</ html >

  • Filename: connectedness.php

PHP

<?php

$conn = "" ;

try {

$servername = "localhost:3306" ;

$dbname = "geeksforgeeks" ;

$username = "root" ;

$password = "" ;

$conn = new PDO(

"mysql:host=$servername; dbname=geeksforgeeks" ,

$username , $password

);

$conn ->setAttribute(PDO::ATTR_ERRMODE,

PDO::ERRMODE_EXCEPTION);

}

catch (PDOException $e ) {

echo "Connection failed: " . $e ->getMessage();

}

?>

  • Filename: login.css

CSS

torso {

margin : 0 ;

padding : 0 ;

font-family unit : sans-serif ;

background : url () no-echo ;

background- size : encompass;

}

.login-box {

width : 280px ;

position : absolute ;

peak : l% ;

left : 50% ;

transform: interpret( -fifty% , -50% );

color : #191970 ;

}

.login-box h 1 {

bladder : left ;

font-size : 40px ;

edge-bottom : 4px solid #191970 ;

margin-bottom : 50px ;

padding : 13px ;

}

.textbox {

width : 100% ;

overflow : subconscious ;

font-size : 20px ;

padding : 8px 0 ;

margin : 8px 0 ;

border-lesser : 1px solid #191970 ;

}

.fa {

width : px;

bladder : left ;

text-align : center ;

}

.textbox input {

border : none ;

outline : none ;

background : none ;

font-size : 18px ;

float : left ;

margin : 0 10px ;

}

.button {

width : 100% ;

padding : 8px ;

color : #ffffff ;

background : none #191970 ;

border : none ;

border-radius: 6px ;

font-size : 18px ;

cursor : arrow ;

margin : 12px 0 ;

}

  • Filename: validate.php

PHP

<?php

include_once ( 'connection.php' );

function test_input( $data ) {

$data = trim( $information );

$information = stripslashes ( $data );

$data = htmlspecialchars( $data );

return $data ;

}

if ( $_SERVER [ "REQUEST_METHOD" ] == "POST" ) {

$username = test_input( $_POST [ "username" ]);

$password = test_input( $_POST [ "password" ]);

$stmt = $conn ->prepare( "SELECT * FROM adminlogin" );

$stmt ->execute();

$users = $stmt ->fetchAll();

foreach ( $users as $user ) {

if (( $user [ 'username' ] == $username ) &&

( $user [ 'password' ] == $password )) {

header( "location: adminpage.php" );

}

else {

echo "<script linguistic communication='javascript'>" ;

repeat "alert('WRONG Data')" ;

repeat "</script>" ;

die ();

}

}

}

?>

  • Filename: adminpage.php Add together anything that you want to display to the admin page.

HTML

6. After completing all the above steps, now follow the steps:

  • Run XAMPP server
  • Start Apache and MySQL services from XAMPP Console.
  • Blazon http://localhost/loginPage/ in your browser.

You will get the following login page screen.

If you lot enter the correct credentials i.e. username and countersign, then you will exist logged in to the "admin.php" folio.

else, you get an fault pop-up alert.

PHP is a server-side scripting language designed specifically for web development. Y'all tin acquire PHP from the ground upward by following this PHP Tutorial and PHP Examples.


How To Create Unique Url For Each Of My Sites Registered Users With Php,

Source: https://www.geeksforgeeks.org/how-to-create-admin-login-page-using-php/

Posted by: salinasdelitth.blogspot.com

0 Response to "How To Create Unique Url For Each Of My Sites Registered Users With Php"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel