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 Secure login
Contents shared By educratsweb.com

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
1. AnyDesk : Remote Desktop Software| Connect to a computer remotely
2. Study showing stars of varied ages can co-exist in open clusters, provides clue to stellar evolution in the Milky Way Galaxy
3. IACS Kolkata INSPIRE faculty’s work on Black Holes and Gravitational Waves to help understanding fundamentals of our nature
4. Detection of fluorine in hot Extreme Helium Stars solves their evolution mystery
5. NCSTC, DST in association with Vigyan Prasar organized watching of Solar Eclipse live with solar filter spectacles in the campus
6. IMD Weather Services VIA UMANG Mobile App
7. DST-SERB supports study for identification of structure-based potential antivirals against COVID 19
8. Chinese hackers attempt over 40,000 cyber-attacks in 5 days on India: Maha Police
9. IT Minister Launches National AI Portal of India- www.ai.gov.in
10. 7 services hosted on http://mausam.imd.gov.in web site of IMD have been onboarded to UMANG Application
11. Live telecast of the solar eclipse has been arranged via Zoom, YouTube and Facebook
12. Researchers find a new possibility to improve rice productivity
13. Prime Minister pays tributes to scientists on the National Technology Day
14. Certifying Quantum Entanglement: A step towards Quantum Security
15. The system has been certified for safety and performance by NABL accredited agencies and undergone stringent biomedical tests
16. Aarogya Setu is now open source
17. 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
18. NIT Kurukshetra Implements Enterprises Resource Planning (ERP), SAMARTH
19. Ministry of MSME Launches CHAMPIONS Portal www.Champions.gov.in
20. National Technology Day to be celebrated focusing on rebooting the economy through S&T
21. DRDO develops bio suit with seam sealing glue to keep health professionals fighting COVID-19 safe
22. Computer based nano materials by INST Mohali can show the future of nano-electronics
23. Scientists observe celestial smash-up around nearby star
24. Make a Free Website through Google Sites
25. AarogyaSetu: A multi-dimensional bridge
26. National Laboratory Directory
27. AnyDesk Software
28. 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
29. A To Z List of Linux Commands
30. What is an API? (Application Programming Interface)
31. 9 commands to check hard disk partitions and disk space on Linux
32. 5 Ways To Redirect A Website URL
33. BOOST YOUR WINDOWS PC SPEED / INCREASE COMPUTER SPEED
34. Extracting Data from Dynamic Websites in Real Time
35. Top 20 Web Crawling Tools to Scrape the Websites Quickly
36. Buy Redmi 6 Pro starts from Rs.10999
37. Agricultural Technology Information Centre (ATIC)
38. Php code example for login
39. Agricultural Technology Information Centre (ATIC)
40. nofollow : Concept and specification
41. BEST WAY TO COLLECT PAYMENTS ON YOUR WEBSITE
42. Php code for Online Quiz
43. Agricultural Technology Information Centre (ATIC)
44. HTML – Hyper Text Markup Language
45. OPPO R17 PRO : फ़ास्ट चार्ज होगी बैटरी
46. Php code example for Secure login
47. Php code for Online Quiz
48. 9 Emerging Technologies to Lookout for in 2019
49. गूगल फोन पर भारी डिस्काउंट
50. 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=58 http://educratsweb.com educratsweb.com educratsweb