My host is not VPS. Today I create this code:
index.php
<?php
require 'Controllers/router.php';
$router=new Router();
$router->run();
================================
Views/login.php
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Projeto PHP</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<style>
html,body {height: 100%}
body {display: flex;align-items: center;padding-top: 40px;padding-bottom: 40px;background-color: #f5f5f5;}
.form-signin {max-width: 330px;padding: 15px;}
.form-signin .form-floating:focus-within {z-index: 2;}
</style>
<body class="text-center">
<main class="form-signin w-100 m-auto">
<form method=post>
<h1 class="h3 mb-3 fw-normal">Projeto PHP</h1>
<div><?=$mensagem?></div>
<div class="form-floating">
<input type="email" class="form-control" name=email
placeholder="[email protected]" value='<?=$value?>' autofocus required>
<label for="floatingInput">Email</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Senha" name="senha" required>
<label for="floatingPassword">Senha</label>
</div>
<button class="w-100 btn btn-lg btn-primary" type="submit">Entrar</button>
</form>
</main></body></html>
=============================================================
Controllers/router.php
<?php
class Router {
private $routes = [],$controle;
public function __construct(){
require 'Controllers/controle.php';
$this->controle=new controle();
$this->addRoute('GET','/',function(){
$this->controle->inicio();});
$this->addRoute('POST','/',function(){
$this->controle->login();});
$this->addRoute('GET','/orcamento',function(){
$this->controle->orcamento();});
}
public function addRoute($method, $path, $handler) {
// $method is the HTTP method (e.g., GET, POST, PUT, DELETE)
// $path is the route path (e.g., '/', '/about', '/contact')
// $handler is the route handler (a callable function or object)
$this->routes[$method][$path] = $handler;}
public function run() {
// Get the current request method and path
$method = $_SERVER['REQUEST_METHOD'];
$path = $_SERVER['REQUEST_URI'];
// Find the matching route
$route = $this->routes[$method];
if (!array_key_exists($path, $route)) {
throw new Exception('No route found for method ' . $method .
' and path ' . $path);}
// Call the route handler
$handler = $route[$path];
$handler();}}
===============================================================
Controllers/controle.php
<?php
class controle{
private $conexao;
public function __construct(){
require_once 'Models/conexao.php';
$this->conexao=new conexao();
return $this->conexao;}
public function inicio(){
date_default_timezone_set('America/Sao_Paulo');
$inicio=date('H:i');
return $this->conexao->render('login',['mensagem'=>$inicio,'value'=>'']);}
public function login(){
$email=$_POST['email'];
$senha=$_POST['senha'];
unset($_POST);
$row=$this->conexao->unico("select * from users where email='$email'");
if(!$row||$row==0){
$this->conexao->render('login',
["mensagem"=>"Email $email incorreto!","value"=>$email]);exit;}
$dbSenha=$row['password'];
if(!password_verify($senha,$dbSenha)){
$this->conexao->render('login',
['mensagem'=>'Senha incorreta!','value'=>$email]);exit;}
session_start();
$_SESSION['nome']=$row['name'];
$_SESSION['id']=$row['id'];
unset($_GET);
$this->conexao->render('menu');exit;}
public function orcamento(){
echo "projeto em andamento...";
}
}
It works very well in my local machine, after active PHP server by comand php -S localhost:8000
but in Hostinger i get HTTP ERROR 500 this page not working.
I need change hosting plan or I missed something in the way?