Secondary menu

Skip to primary content
Skip to secondary content
  • Home
  • Contact Us
  • About Us

MyCoding.net

Programming Made Easy!

Main menu

Skip to primary content
Skip to secondary content
  • Site News
  • Java
  • C/C++
  • C#
  • PHP
  • Android
  • How to
  • Miscellaneous

Post navigation

← Previous Next →

PHP simple login script

Posted on November 27, 2011 by Vlad

This script is just the implementation of previous post which explains how to retrieve information from user through html forms. We will be needing two files, first the login.html file to display our HTML form and the other file login.php to process the input provided by the user. login.php actually processes and decides if the login details provided by the user are correct or not. If the details are correct it shows a “Login Successful” message. There is nothing extraordinary about the code in login.php. It just fetches the values from the form and checks if they are correct using an IF statement.

login.html:

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<form action = "login.php" method = "post">
User: <input type = "text" name = "user">
Password: <input type="password" name = "pass"">
<input type = "submit" value ="Login">
</form>
</body>
</html>

login.php:

PHP
1
2
3
4
5
6
7
8
9
<?php
$user = $_POST['user'];
$pass = $_POST['pass'];
if ($user == 'Vlad' && $pass == '1234'){
    echo 'Login Successful!';
}else {
    echo 'Wrong username/password. Please try again.';
}
?>

  • Bio
  • Latest Posts

Vlad

Latest posts by Vlad (see all)

  • Code jam “Tic-Tac-Toe-Tomek” solution in java - April 19, 2013
  • Code jam “Minimum Scalar product” solution in java - March 18, 2013
  • Code jam Store Credit solution in java - March 10, 2013

Related posts:

  1. Login form in Java using JDBC connectivity
  2. Processing HTML forms in PHP
  3. A simple way to Password Protect your C++ program!
This entry was posted in PHP and tagged login, PHP by Vlad. Bookmark the permalink.

Search


Sponsors



Recent Comments

  • umerali on How To Run a Java Applet using Command Prompt
  • Vlad on Creating simple tables in Java
  • Aitazaz on Creating simple tables in Java
  • Tsakani on Creating simple tables in Java
  • Ernie on Creating simple tables in Java

Recent Posts

  • Netbeans Tutorial – Cookies
  • Code jam “Tic-Tac-Toe-Tomek” solution in java
  • Code jam “Minimum Scalar product” solution in java
  • Code jam Store Credit solution in java
  • Program to find a square of a number without using multiplication or exponential

Join us on Facebook


Popular Posts

  • C++ program to convert decimal number into binary number 42,011 view(s) | by Vlad
  • C++ Program to find the factorial of a number. 34,272 view(s) | by Lalit Mali
  • Login form in Java using JDBC connectivity 28,054 view(s) | by Vlad
  • How to Compile a Java program in Eclipse 21,351 view(s) | by Vlad
  • How To Run a Java Applet using Command Prompt 15,698 view(s) | by Lalit Mali
  • C++ program to find out sum of digits of a number. 14,066 view(s) | by Vlad
  • C++ Program to check if a number is a Prime Number. 11,029 view(s) | by Lalit Mali
  • Caesar Cipher program 10,069 view(s) | by Vlad
  • Applet to make a smiley face 9,768 view(s) | by Vlad
  • Creating simple tables in Java 9,567 view(s) | by Vlad

Recent Comments

  • umerali on How To Run a Java Applet using Command Prompt
  • Vlad on Creating simple tables in Java
  • Aitazaz on Creating simple tables in Java
  • Tsakani on Creating simple tables in Java
  • Ernie on Creating simple tables in Java
© MyCoding.net
Admired Theme
Email
Print