8797 sujets

Développement web côté serveur, CMS

Pages :
Bonjour,

Sur mon site, j'ai une page "pronostics.php" où les visiteurs peuvent pronostiquer sur des matchs de foot. Les résultats de leurs pronostics me sont envoyés par mail.

J'ai intégré le captcha 'Recaptcha" pour plus de sécurité. Désormais, je voudrais savoir comment faire pour que, si le code saisi dans la boîte de texte Recaptcha n'est pas le bon, le formulaire se recharge et donc que le mail ne soit pas envoyé vers ma boîte mail.

Merci de votre aide,
T'as lu ça ?

Server Side (How to test if the user entered the right answer)
The following code should be placed at the top of the verify.php file:

<?php
  require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>
Voici le code de ma page "envoi.php" :


<?php require_once('recaptchalib.php');
$privatekey = "6LeMQMwSAAAAADN-WtNr5pTVJCU1tkfPwcM1Qf93 ";
$resp = recaptcha_check_answer (
$privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]
);
?>
<?php if (!$resp->is_valid) {
echo("Le code de vérification est incorrect, veuillez recommencer vos pronostics");
}
?>


A quel endroit dois-je rajouter un code ? Et quel code ?

Merci,
A la place de ça :


<?php if (!$resp->is_valid) {
echo("Le code de vérification est incorrect, veuillez recommencer vos pronostics");
}


tu mets ça :


<?php if (!$resp->is_valid) {
header("location: tapageprecedente.php");
exit();
}

Modifié par PanPan50 (19 Jan 2012 - 10:35)
J'ai mis ce code :

<?php if (!$resp->is_valid) {

header("location: pronostics.php");

exit();

}
?>


Quand je tape le code correct, tout fonctionne.
Par contre, quand je tape un code incorrect, j'arrive quand même sur la page "envoi.php" et le graphisme de la page s'affiche, mais que jusqu'au niveau du message d'erreur (tout le code que j'ai sur Notepad, après le code que tu m'as donné ne s'affiche pas sur mon navigateur)


J'ai ce message qui s'affiche en même temps sur ma page "envoi.php". C'est normal ?
Warning: Cannot modify header information - headers already sent by (output started at /homez.150/usmeille/www/pronostics/envoi.php:16) in /homez.150/usmeille/www/pronostics/envoi.php on line 456

Merci,
Il faut que le "header("location:")" soit à tout prix devant tout le reste du code, ou pour être plus juste, il faut que le "header", soit devant tout code d'affichage.
J'ai essayé juste après le body, ça fonctionne. Puis j'ai essayé avant le html et ça ne fonctionne pas. Bizarre.

Quand je rentre le bon code, tout fonctionne.

Par contre, quand je rentre un mauvais code ou pas de code du tout, j'atterris sur une page d'erreur :

"Warning: Cannot modify header information - headers already sent by (output started at /homez.150/usmeille/www/pronostics/envoi.php:2) in /homez.150/usmeille/www/pronostics/envoi.php on line 21"

C'est normal ?

Merci de votre aide,
Je ne mets que le head pour le moment car mon code est trop long sinon.. :


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php require_once('recaptchalib.php');
$privatekey = "6LeMQMwSAAAAADN-WtNr5pTVJCU1tkfPwcM1Qf93 ";
$resp = recaptcha_check_answer (
$privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]
);
?>
<?php if (!$resp->is_valid) {
header("location: pronostics.php");
exit();
}
?>
<html><head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
  <link rel="icon" type="image/png" href="../Images/logo/icon.png">
  <style type="text/css">
a {
  text-decoration: none;
}
div#lien:hover {
  text-decoration: underline;
  color: white;
}
td#sous-menu:hover {
  font-weight: bold;
  background-repeat: no-repeat;
  background-position: left center;
}
td#archive:hover {
  background-image: url(../Images/graph/bg_main-container.jpg);
  background-position:  center center;
}
p#hide {
  display: none;
}
.cfrm {
  display: none;
}
td#link_1:hover {
  background-image: url(../Images/graph/all_art01.png);
  background-position:  center center;
  background-repeat: no-repeat;
}
</style><title>US Meilleraie Foot | Jeu Concours</title>  
  <style type="text/css">
td#actu:hover {
  background-image: url(../Images/graph/fond_gris_transparent.png);
  background-position:  center center;
}
td#menu:hover {
  font-weight: bold;
  background-position:  center center;
  background-repeat: no-repeat;
  text-decoration: underline;
}
div#une:hover {
  background-position: left center;
  background-repeat: repeat;
  font-weight: bold;
}
div#home:hover {
  font-weight: inherit;
}
  </style><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head>


Désolé, je bricole pour faire coder donc ça ne doit pas être très lisible


<?php require_once('recaptchalib.php');

$privatekey = "6LeMQMwSAAAAADN-WtNr5pTVJCU1tkfPwcM1Qf93 ";

$resp = recaptcha_check_answer (

$privatekey,

$_SERVER["REMOTE_ADDR"],

$_POST["recaptcha_challenge_field"],

$_POST["recaptcha_response_field"]

);

?>

<?php if (!$resp->is_valid) {

header("location: pronostics.php");

exit();

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">

  <link rel="icon" type="image/png" href="../Images/logo/icon.png">

  <style type="text/css">

a {

  text-decoration: none;

}

div#lien:hover {

  text-decoration: underline;

  color: white;

}

td#sous-menu:hover {

  font-weight: bold;

  background-repeat: no-repeat;

  background-position: left center;

}

td#archive:hover {

  background-image: url(../Images/graph/bg_main-container.jpg);

  background-position:  center center;

}

p#hide {

  display: none;

}

.cfrm {

  display: none;

}

td#link_1:hover {

  background-image: url(../Images/graph/all_art01.png);

  background-position:  center center;

  background-repeat: no-repeat;

}

</style><title>US Meilleraie Foot | Jeu Concours</title>  

  <style type="text/css">

td#actu:hover {

  background-image: url(../Images/graph/fond_gris_transparent.png);

  background-position:  center center;

}

td#menu:hover {

  font-weight: bold;

  background-position:  center center;

  background-repeat: no-repeat;

  text-decoration: underline;

}

div#une:hover {

  background-position: left center;

  background-repeat: repeat;

  font-weight: bold;

}

div#home:hover {

  font-weight: inherit;

}

  </style>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>

c_bou98 a écrit :
Non ça ne change rien. Le problème vient du header(location) je pense, non ?


T'as quoi comme message d'erreur là ?
Le même :

"Warning: Cannot modify header information - headers already sent by (output started at /homez.150/usmeille/www/pronostics/envoi.php:2) in /homez.150/usmeille/www/pronostics/envoi.php on line 21"
Non, je n'ai pas d'espace qui traîne.. L'erreur se trouve forcément dans ce code, mais où ?


<?php require_once('recaptchalib.php');
$privatekey = "6LeMQMwSAAAAADN-WtNr5pTVJCU1tkfPwcM1Qf93 ";
$resp = recaptcha_check_answer (
$privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]
);
?>
<?php if (!$resp->is_valid) {
header("location: pronostics.php");
exit();
}
?>


Je vais ré-expliquer mon problème si ça peut t'aider :

J'ai une page de pronostics (pronostics.php) avec un captcha. Si l'utilisateur écrit le bon code, il est envoyé sur la page "envoi.php", et s'il écrit un mauvais code ou rien, je veux qu'il reste sur cette page "pronostics.php".
Pages :