WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Random Number generation using PHP's GD technique (captcha).
Categories : PHP, GD image library, Graphics, Security
Chetankumar Akarte
Date : Jan 23rd 2007
Grade : 3 of 5 (graded 1 times)
Viewed : 2739
File : 4565.zip
Images : Image 1
Search : More code by Chetankumar Akarte
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

You can use the GD library and the relevant PHP functions to generate images. This script is helpful to generate a security number image (CAPTCHA). Each time the page is refreshed a new number is Generated.

imagecreate() - Create a new palette based image,imagecreate() returns an image identifier representing a blank image of size x_size by y_size. (http://www.weberdev.com/imagecreate)

imagecolorallocate() - Allocate a color for an image. imagecolorallocate() returns a color identifier representing the color composed of the given RGB components. red, green and blue are the values of the red, green and blue component of the requested color respectively. These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. imagecolorallocate() must be called to create each color that is to be used in the image represented by image. (http://www.weberdev.com/imagecolorallocate)

imagefill() - Flood fill,imagefill() performs a flood fill starting at coordinate x, y (top left is 0, 0) with color in the image. (http://www.weberdev.com/imagefill)

imagerectangle() - Draw a rectangle,imagerectangle() creates a rectangle of color col in image image starting at upper left coordinate x1, y1 and ending at bottom right coordinate x2, y2. 0, 0 is the top left corner of the image. (http://www.weberdev.com/imagerectangle)

imagestring() - draws the string s in the image identified by image with the upper-left corner at coordinates x, y (top left is 0, 0) in color col. If font is 1, 2, 3, 4 or 5, a built-in font is used. (http://www.weberdev.com/imagestring)

imagejpeg() - creates the JPEG file in filename from the image image. The image argument is the return from the imagecreatetruecolor() function. (http://www.weberdev.com/imagejpeg)

The filename argument is optional, and if left off, the raw image stream will be output directly. To skip the filename argument in order to provide a quality argument just use a NULL value. By sending an image/jpeg content-type using header(), you can create a PHP script that outputs JPEG images directly.



random_number.php
<?php
global $number,$Scode;
$img_number = imagecreate(130,41);//Control side of Canvas
$white = imagecolorallocate($img_number,255,255,255);
$black = imagecolorallocate($img_number,0,0,0);
$grey_shade = imagecolorallocate($img_number,204,204,204);
imagefill($img_number,0,0,$grey_shade);
ImageRectangle($img_number,5,5,124,35,$black); //Control side of rectangle
ImageRectangle($img_number,0,0,129,40,$black); //Control side of rectangle

$number = get_random();
Imagestring($img_number,9,10,15,$number,$black);

header("Content-type: image/jpeg");
imagejpeg($img_number);

//Session


$Scode = $securitycode;
/*
  techxcel, Open Source E-Commerce Solutions
  Code by Chetankumar Akarte
*/
  // Function    : get_random
  //
  // Arguments   : non
  //
  // Return      : Random number
  //
  // Description : function for generate random number that use to conforms recure User Registration.
  //

 
function get_random()
{
srand(time());
$max = getrandmax();
return
rand(1,$max) + rand(1,$max) ;
}
?>



A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
Generate image with random number (CAPTCHA)
Categories : PHP, GD image library, Graphics, Security
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session.
Categories : PHP, GD image library, Form Processing, Security
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Line graphics generation library written in PHP + GD library (spanish comments)
Categories : PHP, Graphics, GD image library
Simple PHP Bar Graph using GD library
Categories : PHP, GD image library, Graphics, Arrays
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
Dynamic Image Authentication System in Signup Pages (CAPTCHA)
Categories : PHP, Security, GD image library
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics
 matthew waygood wrote : 1677
Similar to http://www.developerfusion.co.uk/show/1951/4/

&lt;?php 

//random_number.php 
$img_number = imagecreate(100,50); 
$white = imagecolorallocate($img_number,255,255,255); 
$black = imagecolorallocate($img_number,0,0,0); 
$grey_shade = imagecolorallocate($img_number,204,204,204); 

imagefill($img_number,0,0,$grey_shade); 
ImageRectangle($img_number,5,5,94,44,$black); 
ImageRectangle($img_number,0,0,99,49,$black); 

header("Content-type:image/jpeg"); 
imagejpeg($img_number); 

?&gt; 

 
 matthew waygood wrote : 1678
Sorry, didn`t read the next page on that article. Change my comment from "Similar" to "Exactly"
 
 Chetankumar Akarte wrote :1679
Hi..everybody

I have this script one year,when i was facing problem to generate Random Numbar using php, my friend VIJAY gave me the above script.

i have no idea that this Similar to http://www.developerfusion.co.uk/show/1951/4/ 

i feel that it is unique and created by my friend i requested him and told him that i want to submit it at http://www.weberdev.com... He reply that i can..!! so i submmited it with adding explanation of script 

I heartily Thanks Matthew Waygood for giving me idea about real author of the script...
and i am very Happy to give the Credit to its real Author...
Please follow link  for detail and original Author`s Creation at...
http://www.developerfusion.co.uk/show/1951/1/
Title:-Image Generation on the FLY using PHP

Thank you ance more Matthew Waygood to show me my mistake. i always care to avoid such mistake in future..

Thanks & Regards...
Chetan Akarte