Is it possible to prevent users from accessing a page of type "registar.php? msg = error" per link?
In other words, basically there is the link "register.php" that serves for users to register and the email entered was already a user, clicking the register button, the user will be directed to the link "register.php ? msg = error "which is the same as" register.php "but with a div indicating the error. Is there a way to not allow access to "registar.php? Msg = error" per link? and just by clicking the button?
Code:
registar.php
<div class="banner-bot" >
<div class="container">
<h2>Registar</h2>
<p>Preenche os dados para criar a tua conta. Quando te registares irá ser enviado um email para confirmares a conta. </p>
<br>
<?php
if(isset($_GET["msg"]) && $_GET["msg"] == "erro") {
?>
<div class="alert alert-danger">
<strong>Erro!</strong> Já existe uma conta associada ao email introduzido. Tente novamente com um email diferente.
</div>
<?php
}
?>
<br>
</div>
<form name="registarUtilizador" action="Inserir/InserirUtilizador.php" onsubmit="return validarRegisto()" method="POST">
<div class="register-box">
<div class="text">
<input type="text" placeholder="Nome Completo" required="" name="nomeCompleto" id="nomeCompleto" maxlength="99"/>
<br>
<br>
<input type="text" placeholder="Email" required="" name="email" id="email" maxlength="99"/>
<br>
<br>
<input type="text" placeholder="Confirme o seu Email" required="" name="emailConfirmar" id="emailConfirmar" maxlength="99"/>
<br>
<br>
<input type="password" placeholder="Password" required="" name="pass" id="" maxlength="20"/>
<br>
<br>
<input type="password" placeholder="Confirme a sua Password" required="" name="passConfirmar" id="passConfirmar" maxlength="20"/>
<br>
<br>
<center><div class="g-recaptcha" data-sitekey="key"></div></center>
<br>
<br>
</div>
<div class="text-but">
<input type="submit" name="submit" value="Confirmar"/>
</div>
</div>
</form>
User Input Code:
<?php require '../functions.php'; ?>
<body>
<?php
$nomeCompleto = $_POST["nomeCompleto"];
$email = $_POST["email"];
$pass = $_POST["pass"];
$options = [
'cost' => 12,
];
$pass = password_hash($pass, PASSWORD_BCRYPT, $options);
// Create connection
$conn = db_connect();
$sql = "INSERT INTO utilizadores (nomeCompleto, email, pass)
VALUES ('$nomeCompleto', '$email', '$pass')";
if ($conn->query($sql) === TRUE) {
header("Location: ../index.php?msg=sucesso");
} else {
header("Location: ../registar.php?msg=erro");
}
$conn->close();
?>