Bizzare fonctionne en locale mais pas sur mon serveur
Posté : 03 févr. 2008, 02:19
Bonjour, j'utilise ce petit script pour afficher une image de securité contre les vilain spammer. Bref le code fonctionne sauf pour la fonction noise qui n'affiche rien sur mon serveur (fonctionne chez moi et sur lycos gratuit).
Si il y a quelq'un qui a une idée du probleme.
Merci énormément d'avance.
Ma librairie gd sur mon serveur est installé en voici les composants :
Voici le bout de code qui ne fonctionne pas coté serveur :
Voici le code source complet
Si il y a quelq'un qui a une idée du probleme.
Merci énormément d'avance.
Ma librairie gd sur mon serveur est installé en voici les composants :
Code : Tout sélectionner
GD Support enabled
GD Version 2.0 or higher
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.2.1
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
Code : Tout sélectionner
function addNoise()
{
$width = imagesx($this->image);
$height = imagesy($this->image);
//random dots.
for($i = 0; $i < $this->num_dots; $i++)
{
imagefilledellipse($this->image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $this->noisecolor);
}
}
Code : Tout sélectionner
<?php
session_start();
/**
* SecurityImage.php
*
* Class to implement Captcha security Images
* to combat Spam, using PHP/GD
*
* @author A.D.Surrey. (www.surneo.com)
* @version 1.3
*/
class SecurityImage
{
var $bg,
$image,
$font, // Located in fonts folder.
$fontsize,
$colour, // Colour of text
$strLength, // Length of random Text
$text = "",
$num_dots, // Num of noise dots to add
$chars = array("a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z","1","2","3","4","5","6","7","8","9");
/**
* Constructor, setup initial values.
*
* @return SecurityImage
*/
function SecurityImage()
{
$this->num_dots = 300; // How much Noise to add.
$this->strLength = 5;
$this->fontsize = 18;
$this->selectFont(); // Decide which Font to use.
$bg = "images/" . mt_rand(1,8) . ".png"; // Set bg to use.
$this->image = imagecreatefrompng($bg);
$this->colour = ImageColorAllocate ($this->image, 0, 0, 0); // Black
$this->noisecolor = ImageColorAllocate ($this->image, 0, 0, 0); // Black
/**
* Automatically show when object created.
*/
$this->show();
/**
* Set session varible so our form can compare the text
* to users input
*/
$_SESSION['SECURITY_CODE'] = $this->text;
}
/**
* Display our Captcha image
*
*/
function show()
{
Header ("Content-type: image/png");
$this->text = $this->genString();
/**
* write each letter to image
*/
for($i = 0; $i < $this->strLength; $i++)
{
$this->writeLetter($this->text[$i],(20 + $i * 25));
}
$this->addNoise();
imagepng($this->image);
imagedestroy($this->image);
}
/**
* Generate a random string for our image
* using the caracters in our array.
*
*/
function genString()
{
for ($i = 0; $i < $this->strLength; $i++)
{
$this->text .= $this->chars[mt_rand(0, count($this->chars) - 1)];
}
return $this->text;
}
/**
* writes a single letter to the image, using random angles/colours
*
*/
function writeLetter($letter ,$xvalue)
{
$yvalue = 30 - mt_rand(0, 10); // Randomly adjust y position.
$angle = mt_rand(-30,30);// Give text a slight random angle.
imagettftext($this->image, $this->fontsize, $angle, $xvalue, $yvalue, $this->colour, $this->font, $letter);
}
/**
* Compares the given text to the one in the Security
* Image.
*
* @return true if the text matches.
*/
function isMatch($t)
{
if($t == $this->text)
{
return true;
}
else return false;
}
/**
* function to add extra "noise"
* or random dots to the image
*
*/
function addNoise()
{
$width = imagesx($this->image);
$height = imagesy($this->image);
//random dots.
for($i = 0; $i < $this->num_dots; $i++)
{
imagefilledellipse($this->image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $this->noisecolor);
}
}
/**
* Chose a random TTF Font to use for out Captcha Text.
*
*/
function selectFont()
{
switch (mt_rand(1,7))
{
case 1 : $this->font = "fonts/Acidic.TTF"; break;
case 2 : $this->font = "fonts/arial.ttf"; break;
case 3 : $this->font = "fonts/frizzed.ttf"; break;
case 4 : $this->font = "fonts/STACKZ.TTF"; break;
case 5 : $this->font = "fonts/luggerbu.ttf"; break;
case 6 : $this->font = "fonts/SCRAWL.TTF"; break;
case 7 : $this->font = "fonts/times_new_yorker.ttf"; break;
}
}
}
/**
* Create a new object when we include this file.
*/
$secim = new SecurityImage();
?>
qui s'affiche en haut à gauche de ce sujet