captcha qui affiche pas le code a retaper(resolu)

Eléphant du PHP | 59 Messages

05 sept. 2010, 22:53

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.
Modifié en dernier par aurel08 le 04 oct. 2010, 10:07, modifié 1 fois.
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

Eléphanteau du PHP | 13 Messages

06 sept. 2010, 12:59

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.
http://www.ilbee.net/
Créateur de solution Internet

Eléphant du PHP | 59 Messages

06 sept. 2010, 16:25

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
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

ViPHP
ViPHP | 5462 Messages

07 sept. 2010, 02:45

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

zaltec
Invité n'ayant pas de compte PHPfrance

07 sept. 2010, 15:46

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);
?>

Eléphant du PHP | 59 Messages

07 sept. 2010, 18:36

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
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

ViPHP
ViPHP | 5462 Messages

07 sept. 2010, 19:34

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 ?

Eléphant du PHP | 59 Messages

07 sept. 2010, 19:47

comment on fait?
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

ViPHP
ViPHP | 5462 Messages

07 sept. 2010, 20:26

comment on fait?
a quoi correspondent les valeurs display_errors et error_reporting dans ton phpinfo ?

Eléphant du PHP | 59 Messages

07 sept. 2010, 21:44

alors les voici :

display_errors Off Off
error_reporting 22527 22527

voila
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

ViPHP
ViPHP | 5462 Messages

07 sept. 2010, 22:09

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

Eléphant du PHP | 59 Messages

08 sept. 2010, 04:56

voila ensuite :
display_errors On On
error_reporting 32767 32767
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

zaltec
Invité n'ayant pas de compte PHPfrance

08 sept. 2010, 08:36

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 ?

Eléphant du PHP | 59 Messages

08 sept. 2010, 17:32

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
debian lenny | php5.3.3 | mysql 5.1.51 | apache2.2.16

ViPHP
ViPHP | 5462 Messages

08 sept. 2010, 19:16

ta une erreur dans ton captcha.php, supprime pour header pour voir les erreurs