473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

GD Library Problem

18
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.





Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. session_start();
  3.  
  4. if( isset($_POST['submit'])) {
  5. if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
  6. // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
  7. echo 'Thank you. Your message said "'.$_POST['message'].'"';
  8. unset($_SESSION['security_code']);
  9. } else {
  10. // Insert your code for showing an error message here
  11. echo 'Sorry, you have provided an invalid security code';
  12. }
  13. } else {
  14. ?>
  15.  
  16. <form action="form.php" method="post">
  17. <label for="name">Name: </label><input type="text" name="name" id="name" /><br />
  18. <label for="email">Email: </label><input type="text" name="email" id="email" /><br />
  19. <label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
  20. <img src="CaptchaSecurityImages.php width=100&height=40&characters=5" /><br />
  21. <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br />
  22. <input type="submit" name="submit" value="Submit" />
  23. </form>
  24.  
  25. <?php
  26. }
  27. ?>
------------the second code----------------------
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3.  
  4. /*
  5. * File: CaptchaSecurityImages.php
  6. * Author: Simon Jarvis
  7. * Copyright: 2006 Simon Jarvis
  8. * Date: 03/08/06
  9. * Updated: 07/02/07
  10. * Requirements: PHP 4/5 with GD and FreeType libraries
  11. * Link: http://www.white-hat-web-design.co....php-captcha.php
  12. * This program is free software; you can redistribute it and/or 
  13. * modify it under the terms of the GNU General Public License 
  14. * as published by the Free Software Foundation; either version 2 
  15. * of the License, or (at your option) any later version.
  16. * This program is distributed in the hope that it will be useful, 
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  19. * GNU General Public License for more details: 
  20. * http://www.gnu.org/licenses/gpl.html
  21. *
  22. */
  23.  
  24. class CaptchaSecurityImages {
  25.  
  26. var $font = 'monofont.ttf';
  27.  
  28. function generateCode($characters) {
  29. /* list all possible characters, similar looking characters and vowels have been removed */
  30. $possible = '23456789bcdfghjkmnpqrstvwxyz';
  31. $code = '';
  32. $i = 0;
  33. while ($i < $characters) { 
  34. $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
  35. $i++;
  36. }
  37. return $code;
  38. }
  39.  
  40. function CaptchaSecurityImages($width='120',$height='40',$c haracters='6') {
  41. $code = $this->generateCode($characters);
  42. /* font size will be 75% of the image height */
  43. $font_size = $height * 0.75;
  44. $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
  45. /* set the colours */
  46. $background_color = imagecolorallocate($image, 255, 255, 255);
  47. $text_color = imagecolorallocate($image, 20, 40, 100);
  48. $noise_color = imagecolorallocate($image, 100, 120, 180);
  49. /* generate random dots in background */
  50. for( $i=0; $i<($width*$height)/3; $i++ ) {
  51. imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
  52. }
  53. /* generate random lines in background */
  54. for( $i=0; $i<($width*$height)/150; $i++ ) {
  55. imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
  56. }
  57. /* create textbox and add text */
  58. $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
  59. $x = ($width - $textbox[4])/2;
  60. $y = ($height - $textbox[5])/2;
  61. imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
  62. /* output captcha image to browser */
  63. header('Content-Type: image/jpeg');
  64. imagejpeg($image);
  65. imagedestroy($image);
  66. $_SESSION['security_code'] = $code;
  67. }
  68.  
  69. }
  70.  
  71. $width = isset($_GET['width']) ? $_GET['width'] : '120';
  72. $height = isset($_GET['height']) ? $_GET['height'] : '40';
  73. $characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
  74.  
  75. $captcha = new CaptchaSecurityImages($width,$height,$characters); 
  76.  
  77. ?>
Jul 21 '07 #1
5 1330
pbmods
5,821 Expert 4TB
Heya, Akkad.

Is your script generating any errors? See this thread.
Jul 21 '07 #2
kovik
1,044 Expert 1GB
Your image src doesn't make sense. Did you forget to put a question mark at the start of your query string?
Jul 21 '07 #3
nathj
938 Expert 512MB
Hi,

I have recently deployed this code and I had to make s lightchange to it. The line that defines $_SESSION['secutiy_code'] works a lot better and more reliably if you move it from CaptchSecurityImages() to generateCode(), immediatly before the return.

This was the only way I could get the $_SESSION to validate later on.

I just thought I would pass this on as a quick tip.

As for the image not displaying it is also important that the CaptchaSecurityImages.php file is in the same directory as the php page that is using it.

Finally, double check whether the GD libraries are installed correctly and are available. This caused me a bit of bother at first but now it works just fine.

These are all just in case adding '?' into you img src doesn't work. That should definitley be there

Cheers
nathj
Jul 23 '07 #4
Akkad
18
Hi everyboy , thanx for the replies:

1. the quesiton mark is there when i am calling the CaptchaSecurityImages.php:
< img src="CaptchaSecurityImages.php?width=100&height=40 &characters=5" />
2.i have made the changes related to the $_SESSION['security_code'] ;
3. also i added the lines:
error_reporting(E_ALL);
ini_set('display_errors', True);
but there is no error in the form page , or in the from processing page.
4.issues related to GD library installation checking , if some one can just inform me about the installation of GD library on Fedora and what are the libraries needed for proper working of this library and how to enable it from php.ini , in detailed way plz
Jul 23 '07 #5
kovik
1,044 Expert 1GB
If you aren't getting any errors, GD is likely working fine.
Jul 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Simon | last post by:
Hello. I wanna use my dynamic shared library(built with C language) with php script. (PHP version is 4.0.6) So I making a shared library(*.so) in Solaris environment(2.7) and it is successful....
5
by: Venky | last post by:
We have a strange error here. We have an application that is built in VC++ 6.0 and uses a C library built using the same. Now, we have migrated to .Net and have used the same source code to be...
3
by: Tee | last post by:
Hi guys, I have a problem with my VS project, it keeps saying COM Interop registration failed. Could not find a type library for assembly 'Class1'. If I choose to continue, everything still work...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
4
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r)...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
7
by: akennis | last post by:
First of all, sorry for duplicating this post. I put it up in the alt.comp.lang.learn.c-c++ mistakenly. I'm investigating a problem whereby exceptions thrown from functions in a Shared Library...
0
by: drawing in aspnet | last post by:
Question about putting the data layer in a separate class library. I keep reading that the data layer should be separated from the presentation layer and put in its own class library. I am...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.