ok let met tell u what is the problem , i have downloaded the GD library code from interent and when i am using it the picture is not appearing on the page. i don't know why ?
i am using PHP 4.3.9 on Appache server under linux operating system ( fedora 3).
though the same code it is working on the localhost (WAMP) with php 5.2 and apche 2.2
so plz if someone have an idea about the problem plz answer me.
[code=php]
<?php
session_start() ;
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSIO N['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>
<form action="form.ph p" method="post">
<label for="name">Name : </label><input type="text" name="name" id="name" /><br />
<label for="email">Ema il: </label><input type="text" name="email" id="email" /><br />
<label for="message">M essage: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
<img src="CaptchaSec urityImages.php width=100&heigh t=40&characters =5" /><br />
<label for="security_c ode">Security Code: </label><input id="security_co de" name="security_ code" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
?>[/code]
------------the second code----------------------
[code=php]
<?php
session_start() ;
/*
* File: CaptchaSecurity Images.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 07/02/07
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co....ph p-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
class CaptchaSecurity Images {
var $font = 'monofont.ttf';
function generateCode($c haracters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfgh jkmnpqrstvwxyz' ;
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possibl e, mt_rand(0, strlen($possibl e)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurity Images($width=' 120',$height='4 0',$c haracters='6') {
$code = $this->generateCode($ characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($w idth, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_col or = imagecoloralloc ate($image, 255, 255, 255);
$text_color = imagecoloralloc ate($image, 20, 40, 100);
$noise_color = imagecoloralloc ate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$hei ght)/3; $i++ ) {
imagefilledelli pse($image, mt_rand(0,$widt h), mt_rand(0,$heig ht), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$hei ght)/150; $i++ ) {
imageline($imag e, mt_rand(0,$widt h), mt_rand(0,$heig ht), mt_rand(0,$widt h), mt_rand(0,$heig ht), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($f ont_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($i mage, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($imag e);
imagedestroy($i mage);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurity Images($width,$ height,$charact ers);
?>[/code]
i am using PHP 4.3.9 on Appache server under linux operating system ( fedora 3).
though the same code it is working on the localhost (WAMP) with php 5.2 and apche 2.2
so plz if someone have an idea about the problem plz answer me.
[code=php]
<?php
session_start() ;
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSIO N['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>
<form action="form.ph p" method="post">
<label for="name">Name : </label><input type="text" name="name" id="name" /><br />
<label for="email">Ema il: </label><input type="text" name="email" id="email" /><br />
<label for="message">M essage: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
<img src="CaptchaSec urityImages.php width=100&heigh t=40&characters =5" /><br />
<label for="security_c ode">Security Code: </label><input id="security_co de" name="security_ code" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
?>[/code]
------------the second code----------------------
[code=php]
<?php
session_start() ;
/*
* File: CaptchaSecurity Images.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 07/02/07
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co....ph p-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
class CaptchaSecurity Images {
var $font = 'monofont.ttf';
function generateCode($c haracters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfgh jkmnpqrstvwxyz' ;
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possibl e, mt_rand(0, strlen($possibl e)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurity Images($width=' 120',$height='4 0',$c haracters='6') {
$code = $this->generateCode($ characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($w idth, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_col or = imagecoloralloc ate($image, 255, 255, 255);
$text_color = imagecoloralloc ate($image, 20, 40, 100);
$noise_color = imagecoloralloc ate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$hei ght)/3; $i++ ) {
imagefilledelli pse($image, mt_rand(0,$widt h), mt_rand(0,$heig ht), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$hei ght)/150; $i++ ) {
imageline($imag e, mt_rand(0,$widt h), mt_rand(0,$heig ht), mt_rand(0,$widt h), mt_rand(0,$heig ht), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($f ont_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($i mage, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($imag e);
imagedestroy($i mage);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurity Images($width,$ height,$charact ers);
?>[/code]
Comment