PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Juan Camacho   Nano PHP Framework   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Nano PHP Framework
Build applications with the minimum amount of code
Author: By
Last change:
Date: 10 months ago
Size: 871 bytes
 

Contents

Class file image Download
<?php

require_once 'src/Config/Database.php';
require_once
'src/Controllers/AuthController.php';

use
src\Controllers\AuthController;


// Handle login form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'], $_POST['password'])) {
   
$authController = new AuthController();

   
$username = $_POST['username'];
   
$password = $_POST['password'];

   
$user = $authController->login($username, $password);

    if (
$user) {
       
print_r($user);
       
// Successful login, token and cookie are generated.
        // Redirect to the protected page or handle the result accordingly
       
header('Location: protected_page.php');
        exit();
    } else {
       
// Handle login failure, show error message
       
$errorMessage = 'Invalid username or password';
    }
}

// Render the login form
include 'src/views/login.php';

?>