1
I had deploying the user-friendly url in a project to test, so I decided to deploy in TCC, but something is happening that I can’t detect what it is. When I upload the site in /
he opens the sign-in.php
good, the business is when redirects, the form has in action verificaLogin
, but it clicks on the url all the way along with the extension. And on this verificalogin.php
if it goes wrong, he should return to sign-in.php
, and back, but click on the url index.php
, thing I didn’t want. And if it works out, he should go to pag_Contratos
, that page is on view
, but it is carrying /model/pag_Contratos
, and should carry only pag_Contratos
and with the right path. And in case I type a wrong url, it goes to the 404 error page, and when I click back to the main page, it goes to loads home
, I put it to carry sign-in
. As I said, I used this from another project, does it have something to do? Even changing the links?
Codes:
.htaccess (is at the root)
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
index.php (is at the root)
$home = 'view/sign-in';
$url = (isset($_GET['url'])) ? $_GET['url'] : $home;
if ($url != $home) {
$dir = 'view/';
$url = array_filter(explode('/', $url));
$url = $dir. $url[0] . '.php';
}
// var_dump($url);
echo $url;
if (file_exists($url)) {
include_once $url;
} else {
include_once 'view/404.php';
}
Sign-in.php (is in view):
<form class="form-signin" method="post" action="verificaLogin">
<h1 class="h1-large">Login</h1>
<label for="inputEmail" class="sr-only">Endereço de E-mail</label>
<input type="text" name="txtu" maxlength="50" class="form-control" placeholder="Nome de Usuário"/>
<br>
<label for="inputPassword" class="sr-only">Senha</label>
<input type="password" name="txts" class="form-control" placeholder="Senha">
<br>
<div class="checkbox mb-3">
<label class="p-small">
<input type="checkbox" value="remember-me"> Lembrar minha senha
</label>
</div>
<br>
</form>
verificaLogin.php (is in model):
require_once 'conexao.php';
require_once 'banco-login.php';
require_once 'banco-chamado.php';
if ($_POST) {
$user = $_POST['txtu'];
$senha = $_POST['txts'];
session_start();
if (efetuarLogin($conexao, $user, $senha)) {
session_start();
$_SESSION['nome'] = $user;
$cpf = pegaCpfUsuarioLogado($conexao, $user);
$_SESSION['tipoUsuario'] = pegaTipoUsuario($conexao, $cpf);
mysqli_close($conexao);
if ($_SESSION['tipoUsuario'] == 2) {
$_SESSION['log'] = 'ativo';
header("location: pag_contratosCli");
} else {
$_SESSION['log'] = 'ativoTecnico';
header("location: pag_contratosTec");
}
} else {
echo '<script> var r = confirm("Senha ou usuário incorreto!")
if (r === true) {
window.location.assign("sign-in");
} else {
window.location.assign("sign-in");
}
</script>';
}
}
404.php (is in view)
<html>
<head>
<title>404</title>
<meta charset="utf-8">
</head>
<body>
<h1>Página não encontrada</h1>
<a href="sign-in">Retornar a Home</a>
</body>
</html>
I suggest you start thinking about using a JS framework to manage your SPA, recommend Vue (simpler, if you don’t know much about front) or Angular (more complete, if you already have more or less a notion of what you are doing). Doing this management in the back is usually more complicated and costly (performance)
– Costamilam