par
Farah DOUIBI » 15 mai 2015, 17:46
Bonjour,
Je déterre ce sujet, car j'ai EXACTEMENT le même problème.
Je précise que j'ai un site en php 5.3 et un autre en php 5.4.
Mon code affiche bien l'image de sécu depuis des années sur le site en php 5.3, mais j'ai créé un site en php 5.4 et j'ai mi la fonction dessus, l'image ne s'affiche pas dessus.
OVH me dit de mettre le .htaccess qui va bien pour forcer le php 5.3 : SetEnv PHP_VER 5_3, et hop le code fonctionne, et l'image s'affiche !
Mais voilà, cette version va être supprimée en septembre, dans 4 mois...
Et en repassant en php 5.4, l'image ne s'affiche plus, sur les deux sites...
Pour que vous voyiez, le site en php 5.4 :
http://www.farahdouibi.fr/index.php?page=1 => puis cliquez en bas d'une actualité sur "Cliquez ici pour commentez".
Et le site en php 5.3 :
http://www.valeriesimon.fr/index.php?page=1 => puis cliquez en bas d'une actualité sur "Cliquez ici pour commentez".
Mon code :
dans imagesecu.php
<?php
// OUVERTURE DE SESSION POUR $_SESSION['code_image']
session_start();
// on créé une image vide (L , H)
$img = imagecreatetruecolor(200 , 60);
// Couleur de l'image
//$fond = imagecolorallocate($img, 236, 217, 187);
$fond = imagecolorallocate($img, 255, 255, 255);
// Création du rectangle
imagefilledrectangle($img, 0, 0, 199, 59, $fond);
// LISTE DES COULEURS DE POLICE UTILISÉES
// +++++++++++++++++++++++++++++++++
$table_color = array (
imagecolorallocate($img, 80, 39, 6),
imagecolorallocate($img, 23, 71, 91),
imagecolorallocate($img, 106, 27, 53),
imagecolorallocate($img, 21, 99, 39),
imagecolorallocate($img, 81, 82, 7),
imagecolorallocate($img, 0, 0, 0)
);
// +++++++++++++++++++++++++++++++++
// LISTE DES POLICES UTILISÉES
// +++++++++++++++++++++++++++++++++
$table_police = scandir('structure/font');
// +++++++++++++++++++++++++++++++++
// LISTE DES CARACTERES UTILISÉS
// +++++++++++++++++++++++++++++++++
$liste_caracteres = '123456789abcdefghijklmnpqrstuvwxyz';
$table_lettre = array(
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)]
);
// +++++++++++++++++++++++++++++++++
// FONCTION D'ECRITURE ===================================================================================================
$position_en_x = 10;
for($a=0 ; $a<6 ; $a++){
// POLICE DE CARACTERE
$font_de_police = 'structure/font/'.$table_police[rand(2, (count($table_police)-2))];
// COULEUR DE POLICE DE CARACTERE
$couleur_de_police = $table_color[rand(0,5)];
// CONVERTION DE LA COULEUR DE POLICE EN RGB
$color2rgb = str_pad(base_convert($couleur_de_police, 10, 16), 6, 0, STR_PAD_LEFT);
$rgb2array = array(
base_convert(substr($color2rgb, 0, 2), 16, 10),
base_convert(substr($color2rgb, 2, 2), 16, 10),
base_convert(substr($color2rgb, 4, 2), 16, 10),
);
// MODIFICATION DE LA COULEUR RGB POUR L'OMBRE
$couleur_de_police_ombre = imagecolorallocate($img, ($rgb2array[0]+100), ($rgb2array[1]+70), ($rgb2array[2]));
// ANGLE DE ROTATION
$angle = rand(-20,20);
// OMBRE DU CODE
imagettftext($img , 30 , $angle , ($position_en_x+2) , 45 , $couleur_de_police_ombre , $font_de_police , $table_lettre[$a]);
// CODE
imagettftext($img , 30 , $angle , $position_en_x , 43 , $couleur_de_police , $font_de_police , $table_lettre[$a]);
// J'INCREMENTE DE 30 LA POSITION x DE LA LETTRE SUIVANTE
$position_en_x +=30;
}
// ========================================================================================================================
// CREATION DE L'IMAGE PAR L'EN-TÊTE / PAS DE MISE EN CACHE
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Content-type: image/jpeg");
// CREATION DE LA SESSION
$_SESSION['code_image'] = $table_lettre[0].''.$table_lettre[1].''.$table_lettre[2].''.$table_lettre[3].''.$table_lettre[4].''.$table_lettre[5];
// CREATION DE L'IMAGE PHYSIQUE
imagejpeg($img , '' , 100);
// LIBERATION DE LA MEMOIRE
imageDestroy($img);
?>
Mon appel dans functions.php
<form name="formulaire_billet" action="'.$_SERVER['PHP_SELF'].'?page=truc" method="post">
<div>
Votre nom (si non renseigné, vous apparaîtrez comme anonyme)
<input type="text" name="auteur" maxlength="15" />
</div>
Votre commentaire
<textarea name="commentaire"></textarea>
<p>
Code de sécurité à recopier en minuscules :<br />
<img src="imagesecu.php" alt="code de sécurité" /><br />
<input type="text" name="code_securite" maxlength="6" />
</p>
<input type="submit" value="ENVOYER" />
</form>
Je suis dans l'impasse. J'ai vérifié toutes les fonctions utilisées sur php.net. Rien de déprécié, où j'ai mal vu.
Merci de votre aide,
Farah DOUIBI
Bonjour,
Je déterre ce sujet, car j'ai EXACTEMENT le même problème.
Je précise que j'ai un site en php 5.3 et un autre en php 5.4.
Mon code affiche bien l'image de sécu depuis des années sur le site en php 5.3, mais j'ai créé un site en php 5.4 et j'ai mi la fonction dessus, l'image ne s'affiche pas dessus.
OVH me dit de mettre le .htaccess qui va bien pour forcer le php 5.3 : SetEnv PHP_VER 5_3, et hop le code fonctionne, et l'image s'affiche !
Mais voilà, cette version va être supprimée en septembre, dans 4 mois...
Et en repassant en php 5.4, l'image ne s'affiche plus, sur les deux sites...
Pour que vous voyiez, le site en php 5.4 : http://www.farahdouibi.fr/index.php?page=1 => puis cliquez en bas d'une actualité sur "Cliquez ici pour commentez".
Et le site en php 5.3 : http://www.valeriesimon.fr/index.php?page=1 => puis cliquez en bas d'une actualité sur "Cliquez ici pour commentez".
Mon code :
[b]dans imagesecu.php[/b]
[php]<?php
// OUVERTURE DE SESSION POUR $_SESSION['code_image']
session_start();
// on créé une image vide (L , H)
$img = imagecreatetruecolor(200 , 60);
// Couleur de l'image
//$fond = imagecolorallocate($img, 236, 217, 187);
$fond = imagecolorallocate($img, 255, 255, 255);
// Création du rectangle
imagefilledrectangle($img, 0, 0, 199, 59, $fond);
// LISTE DES COULEURS DE POLICE UTILISÉES
// +++++++++++++++++++++++++++++++++
$table_color = array (
imagecolorallocate($img, 80, 39, 6),
imagecolorallocate($img, 23, 71, 91),
imagecolorallocate($img, 106, 27, 53),
imagecolorallocate($img, 21, 99, 39),
imagecolorallocate($img, 81, 82, 7),
imagecolorallocate($img, 0, 0, 0)
);
// +++++++++++++++++++++++++++++++++
// LISTE DES POLICES UTILISÉES
// +++++++++++++++++++++++++++++++++
$table_police = scandir('structure/font');
// +++++++++++++++++++++++++++++++++
// LISTE DES CARACTERES UTILISÉS
// +++++++++++++++++++++++++++++++++
$liste_caracteres = '123456789abcdefghijklmnpqrstuvwxyz';
$table_lettre = array(
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)],
$liste_caracteres[rand(0,33)]
);
// +++++++++++++++++++++++++++++++++
// FONCTION D'ECRITURE ===================================================================================================
$position_en_x = 10;
for($a=0 ; $a<6 ; $a++){
// POLICE DE CARACTERE
$font_de_police = 'structure/font/'.$table_police[rand(2, (count($table_police)-2))];
// COULEUR DE POLICE DE CARACTERE
$couleur_de_police = $table_color[rand(0,5)];
// CONVERTION DE LA COULEUR DE POLICE EN RGB
$color2rgb = str_pad(base_convert($couleur_de_police, 10, 16), 6, 0, STR_PAD_LEFT);
$rgb2array = array(
base_convert(substr($color2rgb, 0, 2), 16, 10),
base_convert(substr($color2rgb, 2, 2), 16, 10),
base_convert(substr($color2rgb, 4, 2), 16, 10),
);
// MODIFICATION DE LA COULEUR RGB POUR L'OMBRE
$couleur_de_police_ombre = imagecolorallocate($img, ($rgb2array[0]+100), ($rgb2array[1]+70), ($rgb2array[2]));
// ANGLE DE ROTATION
$angle = rand(-20,20);
// OMBRE DU CODE
imagettftext($img , 30 , $angle , ($position_en_x+2) , 45 , $couleur_de_police_ombre , $font_de_police , $table_lettre[$a]);
// CODE
imagettftext($img , 30 , $angle , $position_en_x , 43 , $couleur_de_police , $font_de_police , $table_lettre[$a]);
// J'INCREMENTE DE 30 LA POSITION x DE LA LETTRE SUIVANTE
$position_en_x +=30;
}
// ========================================================================================================================
// CREATION DE L'IMAGE PAR L'EN-TÊTE / PAS DE MISE EN CACHE
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Content-type: image/jpeg");
// CREATION DE LA SESSION
$_SESSION['code_image'] = $table_lettre[0].''.$table_lettre[1].''.$table_lettre[2].''.$table_lettre[3].''.$table_lettre[4].''.$table_lettre[5];
// CREATION DE L'IMAGE PHYSIQUE
imagejpeg($img , '' , 100);
// LIBERATION DE LA MEMOIRE
imageDestroy($img);
?>[/php]
[b]Mon appel dans functions.php[/b]
[php]<form name="formulaire_billet" action="'.$_SERVER['PHP_SELF'].'?page=truc" method="post">
<div>
Votre nom (si non renseigné, vous apparaîtrez comme anonyme)
<input type="text" name="auteur" maxlength="15" />
</div>
Votre commentaire
<textarea name="commentaire"></textarea>
<p>
Code de sécurité à recopier en minuscules :<br />
<img src="imagesecu.php" alt="code de sécurité" /><br />
<input type="text" name="code_securite" maxlength="6" />
</p>
<input type="submit" value="ENVOYER" />
</form>[/php]
Je suis dans l'impasse. J'ai vérifié toutes les fonctions utilisées sur php.net. Rien de déprécié, où j'ai mal vu.
Merci de votre aide,
Farah DOUIBI