educratsweb logo


Php code example for login 

 

Login.php

Create a login.php file where you take input user name and password as shown the figure.
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from form
$myusername=addslashes($_POST['adminuser']);
$mypassword=addslashes($_POST['adminpass']);
$sql="SELECT * FROM admin WHERE adminuser='$myusername' and adminpass='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_adminuser']=$myusername;
header("location: index.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<h2>Login</h2>
<form action="" method="post">
  <label>UserName  : </label>
  <br />
  <input type="text" name="adminuser" id="txtbox"/>
  <br />
  <br />
  <label>Password  : </label>
  <br />
  <input type="password" name="adminpass" class="box" id="txtbox" />
  <br/>
  <br />
  <input type="submit" value=" Submit " id="btn"/>
  <br />
</form>
<div style="font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
</div>

Config.php


Create a configuration file through you connect the mysql databse or any other configuration.
<?php
$mysql_hostname = "localhost";
$mysql_user = "your username ";
$mysql_password = "your password";
$mysql_database = "Your database";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
?>

lock.php


<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_adminuser'];
//$ses_sql=mysql_query("select empuser from employeelogin where empuser='$user_check' ");
//$row=mysql_fetch_array($ses_sql);
$login_admin_session=$user_check;
if(!isset($login_admin_session))
{
header("Location: login.php");
}
?>

index.php


after successful login this is your secure page.
<?php
include('lock.php');
?>
<h2>WELCOME in Login Portal</h2> | <a href=’logout.php’>Logo out</a>

logout.php
after successful login this is your secure page.
<?php
session_start();
if(session_destroy())
{
header("Location: login.php");
}
?>
 

Database Structure

Table name : admin
CREATE TABLE `admin` (
  `adminuser` varchar(20) NOT NULL default '',
  `adminpass` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`adminuser`),
  UNIQUE KEY `adminpass` (`adminpass`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


This is a sample login page. You can modify or use it for your project.

Php code example for login
Contents shared By educratsweb.com

5G How Fast it will Be ? Generation of Wireless Technology in Smartphone Explained ?
Published on Friday June 5 2020
if you have any information regarding Job, Study Material or any other information related to career. you can Post your article on our website. Click here to Register & Share your contents.
For Advertisment or any query email us at educratsweb@gmail.com

RELATED POST
2 IT Minister Launches National AI Portal of India- www.ai.gov.in
3 DST-SERB supports study for identification of structure-based potential antivirals against COVID 19
4 Researchers find a new possibility to improve rice productivity
5 To deal with COVID-19, CIPET to take up R&D initiatives in the areas of Health Care; manufacturing and Certifying PPE and other relevant products as per WHO/ ISO guidelines
6 Aarogya Setu is now open source
7 Certifying Quantum Entanglement: A step towards Quantum Security
8 Prime Minister pays tributes to scientists on the National Technology Day
9 The system has been certified for safety and performance by NABL accredited agencies and undergone stringent biomedical tests
10 NIT Kurukshetra Implements Enterprises Resource Planning (ERP), SAMARTH
11 Ministry of MSME Launches CHAMPIONS Portal www.Champions.gov.in
12 National Technology Day to be celebrated focusing on rebooting the economy through S&T
13 What is an API? (Application Programming Interface)
14 DRDO develops bio suit with seam sealing glue to keep health professionals fighting COVID-19 safe
15 Scientists observe celestial smash-up around nearby star
16 Computer based nano materials by INST Mohali can show the future of nano-electronics
17 Make a Free Website through Google Sites
18 Raksh is a 360-degree proximity detection device that senses other users within its proximity and sounds a warning as soon as another device comes within its defined range
19 AarogyaSetu: A multi-dimensional bridge
20 A To Z List of Linux Commands
21 National Laboratory Directory
22 AnyDesk Software
23 9 commands to check hard disk partitions and disk space on Linux
24 5 Ways To Redirect A Website URL
25 BOOST YOUR WINDOWS PC SPEED / INCREASE COMPUTER SPEED
26 Extracting Data from Dynamic Websites in Real Time
27 Top 20 Web Crawling Tools to Scrape the Websites Quickly
28 Buy Redmi 6 Pro starts from Rs.10999
29 Agricultural Technology Information Centre (ATIC)
30 Agricultural Technology Information Centre (ATIC)
31 Php code example for login
32 BEST WAY TO COLLECT PAYMENTS ON YOUR WEBSITE
33 nofollow : Concept and specification
34 Php code for Online Quiz
35 Agricultural Technology Information Centre (ATIC)
36 OPPO R17 PRO : फ़ास्ट चार्ज होगी बैटरी
37 HTML – Hyper Text Markup Language
38 9 Emerging Technologies to Lookout for in 2019
39 गूगल फोन पर भारी डिस्काउंट
40 Php code example for Secure login
41 Php code for Online Quiz
42 Php Code for View, Search, Edit and Delete Record from MySql Table
We would love to hear your thoughts, concerns or problems with anything so we can improve our website educratsweb.com ! visit https://forms.gle/jDz4fFqXuvSfQmUC9 and submit your valuable feedback.
Save this page as PDF | Recommend to your Friends

http://educratsweb(dot)com http://educratsweb.com/content.php?id=667 http://educratsweb.com educratsweb.com educratsweb