par
Cyrano » 11 févr. 2006, 13:03
Parce que le fichier en question génère une image, pas une page html. Il faut donc procéder différemment. Tu as besoins de deux fichiers:
- Une page php qui va créer la page HTML : affiche_captcha.php;
- le fichier qui va générer l'image captcha.php;
Ça donne ceci:
affiche_captcha.php
<?php
session_start();
$chiffre = rand(120000,600000); // Chiffre aléatoire
$_SESSION['chiffre'] = $chiffre; // Mise en session du chiffre
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" xml:lang="fr" />
<title>Affichage d'une image générée</title>
<meta http-equiv="Content-type" content="image/png" />
</head>
<body>
<img src="./captcha.php" alt="" />
<?php
echo("<p>". $_SESSION['chiffre'] ."</p>");
?>
</body>
</html>
captcha.php
<?php
session_start();
$im = imagecreate (70, 20);
$background_color = imagecolorallocate ($im, 150, 100, 120);
$text_color = imagecolorallocate ($im, 255, 255, 255);
imagestring ($im, 4, 10, 2, $_SESSION['chiffre'], $text_color);
imagepng ($im);
?>
Parce que le fichier en question génère une image, pas une page html. Il faut donc procéder différemment. Tu as besoins de deux fichiers:
- Une page php qui va créer la page HTML : affiche_captcha.php;
- le fichier qui va générer l'image captcha.php;
Ça donne ceci:
[b]affiche_captcha.php[/b]
[php]<?php
session_start();
$chiffre = rand(120000,600000); // Chiffre aléatoire
$_SESSION['chiffre'] = $chiffre; // Mise en session du chiffre
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" xml:lang="fr" />
<title>Affichage d'une image générée</title>
<meta http-equiv="Content-type" content="image/png" />
</head>
<body>
<img src="./captcha.php" alt="" />
<?php
echo("<p>". $_SESSION['chiffre'] ."</p>");
?>
</body>
</html>
[/php]
[b]captcha.php[/b]
[php]<?php
session_start();
$im = imagecreate (70, 20);
$background_color = imagecolorallocate ($im, 150, 100, 120);
$text_color = imagecolorallocate ($im, 255, 255, 255);
imagestring ($im, 4, 10, 2, $_SESSION['chiffre'], $text_color);
imagepng ($im);
?>[/php]