<myPHP>
free PHP scripts

Simple Login System with PHP

Simple login system is a login form is what your can use to login to your website to access restricted content, like a adminpage, With this script you don't need MySqli, But it has i't limits. with this scipt you can only have 1 user.

Okej lefts begin.

First you need to create 2 pages "index.php" and "secretpage.php"

The "index.php" file

<?php
$usererror = "";
$passerror = "";

if(isset($_POST['submit'])) 
{
	$user = "admin";    		// change username
	$pass = "gh3dgue7sber"; 	// change password
	$page = "secretpage.php";       // change secretpage
	
	$username = $_POST['username'];    
	$password = $_POST['password'];   
	
			if($username == $user) { $u_proceed = "1"; } else { $u_proceed = "0"; $usererror = "Wrong username !!!"; }   
			if($password == $pass) { $p_proceed = "1"; } else { $p_proceed = "0"; $passerror = "Wrong password !!!"; }   
	
	if($u_proceed == "1" && $p_proceed = "1") 
		{
	   $_SESSION['loggedin'] = 1;   
		   header('Location: '.$page );
		}  	   
}
?>


<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Simple Login System / myPHP.se</title>
	</head>
	<body>
<div align="center">
		<div style="width: 330px;">
			<h2>Easy Login System</h2>
			<form action="index.php" method="post">
				<input type="text" name="username" placeholder="Username" id="username" required><BR><?php echo $usererror;?><BR>
				<input type="password" name="password" placeholder="Password" id="password" required><BR><?php echo $passerror;?><BR>
				<input type="submit" value="Login" name="submit">
			</form>
		</div>
		</div>
	</body>
</html> 


The "secretpage.php" file
	
<?php
session_start();

if(!isset($_SESSION['loggedin'])) {    
   header('Location: index.php');
   exit();        
}
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>SecretPage / myPHP.se</title>
	</head>
	<body>
<H2>Secret page</H2>
	</body>
</html> 

DOWNLOAD
    Simple Login System