<?php

/**
 * Created by PhpStorm.
 * User: renzo de mesa
 * Date: 8/1/2015
 * Time: 9:45 AM
 */
include_once 'start.php';
$message = "";
$username = "";
if (isset($_POST['submit'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $user = login_attempt($username, $password);
    if ($user) {
        login_success();
        redirect_to('search.php');
    } else {
        $message = 'Username\\Password Incorrect';
    }
}
?>
<div class="container">
<div class="login">
    <?php 
//display message
if ($message != "") {
    echo '<div class="message">' . h($message) . '</div>' . '<br>';
}
?>
Example #2
0
<html>
<head>
	<title>Login page</title>
	<meta charset=utf-8>
	<meta name=viewport content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="style.css">
</head>
<body>
<?php 
session_start();
$username = "";
if (isset($_POST['submit'])) {
    //process form
    $username = $_POST['username'];
    $password = $_POST['password'];
    $found_admin = login_attempt($username, $password);
    if ($found_admin) {
        $_SESSION['user'] = $username;
        echo $_SESSION['user'];
        header("Location: form.php");
    } else {
        echo "<div class='err'>";
        echo "Login failed, try again";
        echo "</div>";
    }
}
function login_attempt($username, $password)
{
    $result = false;
    if (file_exists("admins.csv")) {
        $admins = fopen("admins.csv", "r");