0
I made a site with login, registration and etc. I validated the login and registration with POST method, the site is on the server and everything, but when I put the link of the url already inside the page it loads. Is it some mistake I might have made or is it "normal"?
LOGIN
<form name="formulario" id="formEnvia" action="valida.php" method="POST">
<label >CPF*</label>
<input type="text" id="cpf" name="cpf" class="form-control input-lg" placeholder="000.000.000-00" maxlength="14" pattern="\d{3}\.\d{3}\.\d{3}-\d{2}"
title="Digite o CPF no formato nnn.nnn.nnn-nn" required />
<br>
<label inputemail>E-mail*:</label>
<input type="email" id="inputEmail" name="inputEmail" class="form-control input-lg " placeholder="[email protected]" maxlength="50" required/>
<br>
<button type="submit" onclick="valida_envio()" class="btn btn-primary btn-lg btn-block">
<span class="glyphicon glyphicon-ok"></span>
Acessar</button>
</form>
LOGIN VALIDATION:
<?php
require_once "conexao.php";
$email = $_POST['inputEmail'];
$cpf = $_POST['cpf'];
$query = "SELECT * FROM usuarios WHERE cpf = '$cpf' AND email = '$email'";
$querySelect = mysqli_query($conn,$query);
if(mysqli_num_rows($querySelect) <=0){
echo"<script type='text/javascript'>alert('Email ou cpf incorretos.');window.location.href='index.html';</script>";
die();
}else if(mysqli_num_rows($querySelect) > 0 ){
setcookie("login", $cpf);
header("Location:Postagem.html");
}
What do you mean? You take a url without going through the login and it goes in? That’s it?
– Márcio Cristian
Exactly!!! I put the url and even without login it enters the site
– Maria
Hmmmm, so there really is a security flaw. Are you validating if there is a Session to allow entry to the site? How are you logging in? If possible, edit your post and enter the code.
– Márcio Cristian
Yes. I did the validation with PHP to get the mysql bd. I also did a registration to insert the data in the bd, and all with post method
– Maria
Show, but like, how are you validating if a user has logged in? From what I understand, you have already done the validation to see if there is a user in the bank, right? But that won’t stop someone from calling the internal url without logging in and logging in. What you need to do is validate if the user has logged in using Session. That’s why I wanted to see your login code, to see what you did and if you need to add something...
– Márcio Cristian
Ready. I edited the question and put the codes, if you can take a look...
– Maria
Relax, I’ll edit the answers...
– Márcio Cristian
But pera ae... the page
Postagem.html
has some access restriction?– Wallace Maxters
No... how can I do that?
– Maria
One thing, if you’re dealing with php, you don’t use html, you use the file. php that you will be much more malleable when implementing some code, because you will be able to use the language codes according to the need
– Márcio Cristian