I have a page that we will call pagina.php
with a form. When doing submit
I send the form with <form method="post" action="validar_datos.php">
. Then validar_datos.php
checks that the data entered in the form is correct and if it is sent to the database. Independently, whether the data is correct or not, at the end of the check, redirect the user to the page of the form using header('location:pagina.php?r=1')
if the data is correct or header('location:pagina.php?r=0')
if the data is not correct.
Within pagina.php
I have the following script:
<?php
if(isset($_GET['r'] == 1)){
echo '<div id="message"><p>Nuevo cliente añadido con éxito!</p></div>
<script>$("#message").delay(1500).fadeOut(200);</script>';
}else if($_GET['r'] == 0)){
echo '<div id="message"><p>Datos incorrectos</p></div>
<script>$("#message").delay(1500).fadeOut(200);</script>';
}else{
}
?>
That is, I show a "success" message if the r
index passed by the URL is 1 or an "error" message if the r
index is 0.
When the user is, for example, on the pagina.php?r=1
page, if he reloads the page, the "success" message will appear again and so on as many times as the page refreshes. You could even change the value of r
of the URL to 0 and you would get the message "error".
My question is:
Since I currently use header('location:pagina.php?r=valor')
to redirect the user, is there any way to do it by passing the index r
and its value completely invisible so that the user could not modify it?
And could you make it only show the message once regardless of how many times the page is refreshed?
I hope you explained to me