0
It is possible to prevent users from accessing a "register.php? msg=error" page per link?
That is, basically there is the "register.php" link that serves for users to register and the email entered was already user, by 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 not to let "register.php? msg=error" by link? and just by clicking the button?
Code:
register.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>
Código Inserirutilizador:
<?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();
?>
you can post the code on this register.php page
– user60252
Welcome Nelson Silva, you’ll get better answers if you give people code they can use to reproduce the problem. Read this post https://answall.com/help/mcve
– user60252
I’m sorry, I’ve entered the file code
– Nelson Silva
But is there a link on
registar.php
that toregistar.php?msg=erro
? Or the idea is to "stop" the person writing this directly into the browser url?– Isac
Yes, that was the idea. Try to prevent the person from typing "register.php? msg=error" in the url. And only allow in case the person clicks the button to register.
– Nelson Silva
If any answer solved your problem mark it as accepted, check as and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252