Hi!
I'm redoing a website for a friend and I have to deal with the php scripts already in place and done by somebody a bit like me : who can read and understand php, but not good enough to design something by himself and takes things from different places and put them together to make what he wants.
I have two things that are more or less working, but buggy.
I'm posting here the authentication problem, I'll open a new thread for the other problem as it has nothing to do with authentication.
Basically, here is the thing : a user can register and put his information to be stored in the database.
Registration is fine (inscriptionillu.php), information is collected in the DB like it should, but then, it doesn't return the confirmation page (traitementillu.php).
If a user is already registered, when he tries to connect, on first try he'll get a blank page (like after registration). If he tries again, he'll get the confirmation page alright.
I suspect there might be a session problem, or a problem in the if else statement, but I can't figure out why it's not working.
Those two pages are called inside a third page, with a <? session_start();?> on top of it. Connexion to the database is fine as well. Pathways to the different scripts are fine too.
Here they are :
inscriptionillu.php :
PHP Code:
<? $met=$_POST["met"];
if ($met=="change") { include("connexion.php");
@mysql_connect($host,$user,$pass) or die("Impossible de se connecter"); @mysql_select_db("$bdd") or die("Impossible de se connecter");
<h2 class="titre">Traitement en cours</h2>
<br />
<div align="center">
<?
include("connexion.php");
@mysql_connect($host,$user,$pass)
or die("Impossible de se connecter au serveur");
@mysql_select_db("$bdd")
or die("Impossible de se connecter à la base");
$type=$_POST["type"];
if ($type==1)
{
$table="illustrateurs2";
$mail=$_POST["mail"];
$query = "SELECT * FROM $table WHERE mail='$mail'";
else
{
if ($_POST["password"]==$val['mdp'])
{
$_SESSION['id']=$val['ref'];
$_SESSION['nom']=$val['nom'];
$_SESSION['prenom']=$val['prenom'];
$_SESSION['mail']=$val['mail'];
echo "Vous êtes sur le formulaire d'envoi d'illustrations <br /> aux *****.<br /><br />";
?>
<form name="edit" method="post" action="formillu.php?page=formulaire/inscriptionillu.php">
<input name="met" type="hidden" value="change">
<input name="envoi" value="Mise à jour de votre profil" type="submit">
</form>
<br><br>
<form name="envoie" method="post" action="formillu.php?page=formulaire/infoillu.php">
<input name="envoi" value="Envoi d'un document" type="submit">
</form>
<script language="JavaScript">
//document.location = "http://****.fr/form.php?page=formulaire/info.php";
</script><?
}
else
{
echo "Le mot de passe est erroné.";
echo "Vous pouvez réessayer de vous connecter ou demander l'envoi de votre mot de passe depuis la page de connection.";
?><script language="JavaScript">
window.setTimeout("window.back()",5000);
</script><?
}
}
}
if ($type==2) //entrer ou mise à jour d'un auteur.
{
if($new=="yes") //il s'agit d'un ajout d'auteur
{
if ($val['mail']=="" and $new==true) //si le mail n'est pas dans la base, on peut l'ajouter
{
$query="INSERT INTO illustrateurs2 VALUES('','$nom','$prenom','$password','$pseudo','$site','$mail','$tel','$adresse1','$adresse2','$ville','$codepostal', '$pays','$jour','$mois','$annee', '$noto')";
$result = mysql_query($query);
IF (!$result) { $err=true; $errtxt="Erreur, l'inscription n'a pas fonctionné. Veuillez réessayer ou contacter le webmaster au mail suivant : webmaster@*****.fr<br>".$query;}
ELSE
{
$msg="Inscription réussie. Vous pouvez désormais nous envoyer vos illustrations par le formulaire.";
$query = "SELECT * FROM $table WHERE mail='$mail'";
else //si le mail est dans la base => ERRREUR
{
echo "Le mail entré est déjà dans la base de donnée.";
}
} //fin ajout
else //il s'agit d'une mise à jour
{
$id=$_SESSION['id'];
$query="UPDATE illustrateurs2 SET nom='$nom', prenom='$prenom', mdp='$password', pseudo='$pseudo', site='$site', mail='$mail', tel='$tel', adresse='$adresse1', adresse2='$adresse2',ville='$ville', code='$codepostal', pays='$pays', jour='$jour',mois='$mois',annee='$annee', noto='$noto' WHERE ref='$id'";
$result = mysql_query($query);
IF (!$result) { $err=true; $errtxt="Erreur, la mise à jour n'a pas fonctionné. Veuillez réessayer ou contacter le webmaster au mail suivant : webmaster@*****.fr";}
ELSE { $msg="Votre profil est maintenant mis à jour."; }
} //fin mise à jour
//traitement de l'affichage
if ($err)
{
echo "Erreur lors du traitement : <br>".$errtxt;
}
else
{
echo "Traitement réalisé avec succès.<br><br>".$msg;
?>
<br><br><br>
<form name="edit" method="post" action="formillu.php?page=formulaire/inscriptionillu.php">
<input name="met" type="hidden" value="change">
<input name="envoi" value="Mise à jour de votre profil" type="submit">
</form>
<br><br>
<form name="envoie" method="post" action="formillu.php?page=formulaire/infoillu.php">
<input name="envoi" value="Envoi d'un document" type="submit">
</form>
<?
}
} //fin pas d'erreur dans les champs du formulaire.
}
?>
</div>
For me, it's really painful to have to work with something like that, not really commented and not working, but the friend really wants me to work with this script and not design a new one.
So, any clues about why it's never working on first try but always working on second try ? Is my guess about sessions correct ?
Thanks for all input.
Another question : this script is exactly the same as another script used on the website. When I mean exactly, I really mean exactly. I simply duplicated the files, gave them a new name and had them connect to another table in the db.
The other files work like a charm.
I reviewed everything something like 10 times, but I couldn't find any difference.
What is making the other files work and these ones not work ?
If a user is already registered, when he tries to connect, on first try he'll get a blank page (like after registration).
If he tries again, he'll get the confirmation page alright.
How does the user get to the confirmation page? Via a location header?
If so, I fear there may be HTML getting out before PHP has a chance to delare header information.
For debugging purposes, headers_sent() should prove handy before the part in the script that tries to redirect the user to the confirmation page.
PHP Code:
define("DEBUG_ON",1);//or 0 if(DEBUG_ON && headers_sent()){ echo "<br>Les en-têtes HTTP ont déjà été envoyés!";//correct me if you got another way to say it echo "<br>Abort!"; exit; }
If that is the case then ob_start() would seem like a practical solution to halt the output buffer in case you need to send a location header.
If not, I'll look more closely at the script after you get back to the thread.
?> <br><br><br> <form name="edit" method="post" action="formillu.php?page=formulaire/inscriptionillu.php"> <input name="met" type="hidden" value="change"> <input name="envoi" value="Mise à jour de votre profil" type="submit"> </form> <br><br> <form name="envoie" method="post" action="formillu.php?page=formulaire/infoillu.php"> <input name="envoi" value="Envoi d'un document" type="submit"> </form> <?
}
And the "mother page" has a session_start() at the very top. So, there should be no problem with the html being sent out before, because the headers have already been sent (I guess ?). And normally, when something like that happens, I get the "headers already sent by" error. (BTW, good translation !)
So, basically, the problem is mainly related to the structure of the page, I think. I'll have have to look closely at it. I'll be in Paris for a few days, without access to the website, but I'll be back on Monday. I'll print this out and try to clear this mess a little bit...
But I'll try your code right now !
Thanks for your input !
?> <br><br><br> // from here, this is the part that should be appearing and that's not. <form name="edit" method="post" action="formillu.php?page=formulaire/inscriptionillu.php"> <input name="met" type="hidden" value="change"> <input name="envoi" value="Mise à jour de votre profil" type="submit"> </form> <br><br> <form name="envoie" method="post" action="formillu.php?page=formulaire/infoillu.php"> <input name="envoi" value="Envoi d'un document" type="submit"> </form> <?
}
Last edited by Ness_du_Frat; 12-11-2008 at 04:16 AM.
When you say you get a blank page, how can the HTML before all the if-else statements on traitementillu.php get overlooked?
Surely the blank page would look something more like:
Code:
<h2 class="titre">Traitement en cours</h2>
<br />
<div align="center">
since these words appear at the very top of the PHP file and should render 'Traitement en cours' in big print, no?
Or is the problem that $err is set to true and you get "Erreur lors du traitement : <br>".$errtxt rather than the confirmation part in the final if-else?
Yes, actually, you're right. I get "traitement en cours", and nothing else. My mistake for calling it a blank page... I meant "without the stuff which should actually be on it..."
Sorry ^^
Does this mean that the script never reaches the final if else statement?
Regardless whether $err would be true or false, you'd receive an additional echo.
I think the next stage of debugging the script would be to make sure certain if statements are actually reached in the first place.
It would seem only logical that the script would reach if ($type==2) since the page before it posts that value,
yet perhaps include("connexion.php") preforms some kind of redirect and causes post data to be lost.
That probably isn't the case but you can't be sure.
Use the process of elimination.
Next proceed lower down the page with test echos:
PHP Code:
echo ($_POST["type"]==2)?"so far so good":"type isn't set to 2";
and so on until you narrow it down to where the script stops running.
The only suspicious code I see so far is:
PHP Code:
$mail."<BR>"; $naissance."<BR>";
since you'd generally use = or .= to assign values.
Thanks !
I leave in one hour for Paris, I'll have a good look at that when I'm back.
The strange thing is that it does reach this state, otherwise it wouldn't output the "traitement en cours"... I'll have to test your debugging method.
Bookmarks