Page 1 sur 2

captcha qui affiche pas le code a retaper(resolu)

Posté : 05 sept. 2010, 22:53
par aurel08
bonsoir et bonjour,

alors voila depui aujourd'hui arrive pas a faire aficher le code de mon captcha arrive pas a trouvé le probleme merci de votre aide,:
index1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml/DTD/xhtml1-scrict.dtd">
<html xml:lang="fr" xmlns="http://www.3.org/1999/xhtml">

<?php

session_start();

if (!empty($_POST['captcha'])) {
 if ($_POST['captcha'] == $_SESSION['captcha']) {
   $resultat = '<p>Merci De Votre Message!</p>';
 } else {
	$resultat = '<p>Code incorrect!</p>';
 }
} else {
  $resultat = '<p>veuillez entré le code ci dessou!</p>';
 }
$_SESSION['captcha'] = substr(md5(rand(0.10000).time()),0,6);

?><html>
<head>
<body>
<?php echo $resultat; ?>
<form action="index1.php" method="post">
<img src="captcha.php"><input type="text" name="captcha" value=""><br/>
<input type="submit" value="go" />
</form>

et captcha.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml/DTD/xhtml1-scrict.dtd">
<html xml:lang="fr" xmlns="http://www.3.org/1999/xhtml">

<?php

header(*Content-Type: image/png*);

session_start();
$im = imagecreate(100, 40);

$white = imagecolorallocate($im, 255, 255. 255);
$black = imagecolorallocate($im, 0, 0. 0);

imagettftext($im, rand(13, 25), rand(-30, 30), 0 + 20 * $i + rand(0, 5), 20 + rand(0,10) , $couleur, './WAVY.TTF',
$SESSION['captcha'][$i]);

imagefill($im, 0, 0, $white);

if (!empty($_SESSION['captcha'])) {
 for($i = 0; $i < strlen($_SESSION['captcha']); $i++) {
	$r = rand(0.255);
	$g = rand(0.255);
	$b = sqrt(100 * 100 - $r * $r - $g * $g);
	$couleur = imagecolorallocate($im, $r ,$g,$b);
	imagechar($im, rand(0,4), 0 + 10 * $i + rand(0,5), rand(0,10) ,
	 $_SESSION['captcha'][$i], $couleur);
 }
}

imagepng($im);
imagedestroy($im);
?>
voila la j'ai corriger des erreur mes aucun code s'affiche voic le lien pour que vous voyez par vous meme : http://php.sogames-prod.com/index1.php

j'etait sur un autre site pour demandé de l'aide vraiment de la m**rde on reçois plus de reflection que de l'aide jamais vu sa heuresement que php france est la serieux merci encore de votre aide.

Re: captcha qui affiche pas le code a retaper

Posté : 06 sept. 2010, 12:59
par ilbee
Essaye ca ...
<?
session_start();

header('Content-Type: image/png');

$im = imagecreate(100, 40);

$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagettftext($im, rand(13, 25), rand(-30, 30), 0 + 20 * $i + rand(0, 5), 20 + rand(0,10) , $couleur, './WAVY.TTF', $SESSION['captcha'][$i]);

imagefill($im, 0, 0, $white);

if (!empty($_SESSION['captcha'])) {
	for($i = 0; $i < strlen($_SESSION['captcha']); $i++) {
        $r = rand(0,255);
        $g = rand(0,255);
        $b = sqrt(100 * 100 - $r * $r - $g * $g);
        $couleur = imagecolorallocate($im, $r ,$g,$b); 
        imagechar($im, rand(0,4), 0 + 10 * $i + rand(0,5), rand(0,10) ,
         $_SESSION['captcha'][$i], $couleur);
	}
}

imagepng($im);
imagedestroy($im);
?>
Fais bien attention a faire la différence entre . et , dans les fonctions.
Pense aussi a mettre ton session_start() avant d'envoyer ton header.

Re: captcha qui affiche pas le code a retaper

Posté : 06 sept. 2010, 16:25
par aurel08
ben je vien de le faire c'est pareil sa marche pas de quoi sa peut venir re-voici les code :

index1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml/DTD/xhtml1-scrict.dtd">
<html xml:lang="fr" xmlns="http://www.3.org/1999/xhtml">

<?php

session_start();

if (!empty($_POST['captcha'])) {
 if ($_POST['captcha'] == $_SESSION['captcha']) {
       $resultat = '<p>Merci De Votre Message!</p>';
 } else {
	$resultat = '<p>Code incorrect!</p>';
 }
} else {
  $resultat = '<p>veuillez entré le code ci dessou!</p>';
}
$_SESSION['captcha'] = substr(md5(rand(0.100000).time()),0,6);

?>
<head>
<body>
<?php echo $resultat; ?>
<form action="index1.php" method="post">
<img src="captcha.php"> <input type="text" name="captcha" value=""><br/>
<input type="submit" value="go" />
</form>

et captcha.php
<?php
session_start();

header(*Content-Type: image/png*);

$im = imagecreate(100, 40);

$white = imagecolorallocate($im, 255, 255. 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagefill($im, 0, 0, $white);

if (!empty($_SESSION['captcha'])) {
 for($i = 0; $i < strlen($_SESSION['captcha']); $i++) {
	$r = rand(0,255);
	$g = rand(0,255);
	$b = sqrt(100 * 100 - $r * $r - $g * $g);
	$couleur = imagecolorallocate($im, $r,$g,$b);
	imagechar($im, rand(0,4), 0 + 10 * $i + rand(0, 5), rand(0,10) ,
	 $_SESSION['captcha'][$i], $couleur);
 }
}

imagepng($im);
imagedestroy($im);
?>
merci de votre aide

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 02:45
par stealth35
ta des erreur dans ton code captcha

header(*Content-Type: image/png*);
pourquoi avoir mis des * ?

$white = imagecolorallocate($im, 255, 255. 255);
t'as mis un point au lieu d'une virgules

pareil ici dans dans l'autre fichier
$_SESSION['captcha'] = substr(md5(rand(0.100000).time()),0,6);

le session_start(); n'est pas au bon endroit non plus


affiche les erreurs et bosse avec un vrai editeur sinon tu va jamais t'en sortir

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 15:46
par zaltec
Comme l'a dit stealth35 il faut faire attention au détail : un ' n'est pas un " et une fois ouvertes les balises se referment ;-)
Ceci dit voici un code complété:

index1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml/DTD/xhtml1-scrict.dtd">
<html xml:lang="fr" xmlns="http://www.3.org/1999/xhtml">
<head></head>
<?php
@session_start();

if (!empty($_POST['captcha'])) {
 if ($_POST['captcha'] == $_SESSION['captcha']) {
       $resultat = '<p>Merci de votre message!</p>';
 } else {
        $resultat = '<p>Code incorrect!</p>';
 }
} else {
  $resultat = '<p>Veuillez entrer le code ci-dessous!</p>';
}
$_SESSION['captcha'] = substr(md5(rand(0,100000).time()),0,6);

?>

<body>
<?php 
echo $resultat; ?>
<form action="index1.php" method="post">
<img src="captcha.php"> <input type="text" name="captcha" value=""><br/>
<input type="submit" value="go" />
</form>
</body>
</html>
et
captcha.php
<?php
session_start();
header("Content-Type: image/png");


$im = imagecreate(100, 40);

$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagefill($im, 0, 0, $white);

if (!empty($_SESSION['captcha'])) {
 for($i = 0; $i < strlen($_SESSION['captcha']); $i++) {
        $r = rand(0,255);
        $g = rand(0,255);
        $b = sqrt(100 * 100 - $r * $r - $g * $g);
        $couleur = imagecolorallocate($im, $r,$g,$b);
        imagechar($im, rand(0,4), 0 + 10 * $i + rand(0, 5), rand(0,10) ,$_SESSION['captcha'][$i], $couleur);
 }
}

imagepng($im);
imagedestroy($im);
?>

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 18:36
par aurel08
bonjour,

ben je vien de copier coller rien ne marche j'ai toujour la meme erreur le code s'affiche pas

merci encore de votre aide

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 19:34
par stealth35
bonjour,

ben je vien de copier coller rien ne marche j'ai toujour la meme erreur le code s'affiche pas

merci encore de votre aide
t'affiche les erreurs de php ?

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 19:47
par aurel08
comment on fait?

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 20:26
par stealth35
comment on fait?
a quoi correspondent les valeurs display_errors et error_reporting dans ton phpinfo ?

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 21:44
par aurel08
alors les voici :

display_errors Off Off
error_reporting 22527 22527

voila

Re: captcha qui affiche pas le code a retaper

Posté : 07 sept. 2010, 22:09
par stealth35
display_error est a off donc tu verra jamais les erreurs, faut le mettre a on dans ton php.ini, profite pour mettre le error_reporting a E_ALL | E_STRICT

Re: captcha qui affiche pas le code a retaper

Posté : 08 sept. 2010, 04:56
par aurel08
voila ensuite :
display_errors On On
error_reporting 32767 32767

Re: captcha qui affiche pas le code a retaper

Posté : 08 sept. 2010, 08:36
par zaltec
Quelles sont les erreurs ou warnings qui s'affichent dans le navigateur ?
Quand tu dis le code ne s'affiche pas : s'agit-il juste des images ou bien n'as tu rien sur la page ?
As tu penser a relancer ton serveur apache ? et faire qq tests php avec les dossiers que tu utilises ?

Re: captcha qui affiche pas le code a retaper

Posté : 08 sept. 2010, 17:32
par aurel08
il a rien du tout voici le lien pour voir par vous meme : http://php.sogames-prod.com/index1.php
http://php.sogames-prod.com/captcha.php

Re: captcha qui affiche pas le code a retaper

Posté : 08 sept. 2010, 19:16
par stealth35
ta une erreur dans ton captcha.php, supprime pour header pour voir les erreurs