Php code example for Secure login #educratsweb
HOME | LATEST JOBS | JOBS | CONTENTS | STUDY MATERIAL | CAREER | NEWS | BOOK | VIDEO | PRACTICE SET REGISTER | LOGIN | CONTACT US
Post Jobs or Post Contents Vacancies at Reserve Bank Information Technology Pvt. Ltd. (ReBIT) | Recruitment of Lateral Officers Vacancy in RBI | Recruitment for 10000+ Vacancies in National Health Mission (NHM), Uttar Pradesh (UP) | Govt. Job Vacancies in Nehru Yuva Kendra NYKS | Assam Rifles Technical and Tradesman Recruitment Rally | MPPGCL (Madhya Pradesh Power Generating Company Limited) Recruitment 2018 Post Apply Online | Project Engineer and Assistant Vacancy in National Institute of Wind Energy (NIWE) | Assistant Professor Medical Recruitment by Himachal PSC | Add your Article

Php code example for Secure login

Posted By educratsweb.comTechnology 🗓 Wednesday September 19 2018 👁 164


Php code example for Secure login

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.


RELATED POST

Buy Redmi 6 Pro starts from Rs.10999
Know about Search Engine Optimization
Php Code for View, Search, Edit and Delete Record from MySql Table
Php code example for Secure login
Send E-mail to Multiple Person(E-mail) with Php
HTML – Hyper Text Markup Language
nofollow : Concept and specification
Php code for Comment on Webpage
Php code for Online Quiz
Dual WhatsApp
OPPO R17 PRO : फ़ास्ट चार्ज होगी बैटरी
गूगल फोन पर भारी डिस्काउंट




Disclaimer: we only provide job information. we are not associated with any job website. Although we take extreme care for accuracy of the information provided, but you must check the authenticity of the website before applying for the job. We are not responsible for your operation , once you leave our website and apply thereafter. Please recheck the genuineness of the job website from yourself also.

Copyright © 2018. Website template by WebThemez.com