Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Activation Code Images, How?, need help with activation code images
saga
post Sep 27 2005, 01:14 PM
Post #1


Premium Member
********

Group: Members
Posts: 165
Joined: 12-September 05
Member No.: 11,777



hi everbody,

I am creating this website for an online game KHAN which is of course hosted by Trap17.com. Anyway, it accepts membership since its services includes message board for every member and message board for groups that members created and of course personal messages.

So here is my problem, since it accepts membership it requires applicants to fill up forms which ask their e-mail address, I want to know how make an activation code that is an image. Get my point? smile.gif

it is basically like here in trap17 where before you could click register or submit during registration you need to copy the numbers and letters in an image to a text box. I need this to avoid automated registration which can use up all my 150mb disk space or worst used my registration to annoy other people by using their e-mail add in the registration form.

actualy I was thinking of creating hundreds or more images with numbers and letters on it. Everytime there is need to send the registration form to a browser i will pick 1 image randomly then change its filename randomly and put it in the registration form. In that case images will not use the same filename everytime it is used. But creating all those images (more thatn 100) is more than a headache. Thats why I'm hoping that someone could share to me how this kind of problem realy are taken care of.

Thanks in advance smile.gif
Go to the top of the page
 
+Quote Post
SystemWisdom
post Sep 27 2005, 01:27 PM
Post #2


Advanced Member
*******

Group: Members
Posts: 117
Joined: 3-May 05
From: A Canadian South of the 49th Parallel
Member No.: 6,544



I wrote a script like this not too long ago...

The theory is: You make a random string, save that random string to your sessions (for later comparison), and then generate and output the image..

First, the class file:
CODE

<?php

class TuringImage
{
   // Font Settings
   var $m_szFontFace;
   var $m_iFontSize;
   
   // Image Object
   var $m_oImage;

   // Image Bounds
   var $m_aImageSize;

   // Image Text
   var $m_szImageText;

   function TuringImage()
   {
       // Font Settings
       $this->m_szFontFace = 'fonts/mtcorsva.ttf';
       $this->m_iFontSize  = 20;

       $this->m_oImage = 0;
       $this->m_aImageSize = array( 110, 40 ); // Image Width & Height
       $this->m_szImageText = '';
   }

   function GenerateKey( $iLen )
   {
       $szRandStr = md5( uniqid( rand(), true ) );
       $iRandIdx = rand( 0, (strlen($szRandStr) - $iLen - 1) );
       $szRandStr = substr( $szRandStr, $iRandIdx, $iLen );
       
       // Replace O's and 0's to reduce confusion
       $szRandStr = str_replace( "O", "X", $szRandStr );
       $szRandStr = str_replace( "0", "4", $szRandStr );
       
       $this->m_szImageText = strtoupper( $szRandStr );
       return;
   }

   function GetKey()
   {   return $this->m_szImageText;
   }

   function Create()
   {
       $iTextLen = 5;
       
       // Create Image
       $this->m_oImage = imagecreate( $this->m_aImageSize[0], $this->m_aImageSize[1] );

       // Get Colors
       $oColorFG = imagecolorallocate( $this->m_oImage, 143, 168, 183 );
       $oColorBG = imagecolorallocate( $this->m_oImage, 30, 42, 49 );

       // Set Background Color of Image
       imagefilledrectangle( $this->m_oImage, 0, 0, $this->m_aImageSize[0], $this->m_aImageSize[1], $oColorFG );
       imagefilledrectangle( $this->m_oImage, 1, 1, $this->m_aImageSize[0]-2, $this->m_aImageSize[1]-2, $oColorBG );

       // Obfuscate Image
       $this->ObfuscateImage();
       
       // Write Verification String to Image
       for( $i = 0; $i < $iTextLen; $i++ )
           $this->WriteTTF( (10 + ($i * 18)), (24 + rand(0, 5)), rand(-15, 15), $this->m_szImageText[$i] );
       
       // Output Image to Browser
       imagegif( $this->m_oImage );

       // Free Image Resources
       imagedestroy( $this->m_oImage );
       return;
   }

   function ObfuscateImage()
   {
       $oColor = imagecolorallocate( $this->m_oImage, 143, 168, 183 );
       
       // Random Pixels
       for( $x = 0; $x < $this->m_aImageSize[0]; $x += rand( 3, 7 ) )
           for( $y = 0; $y < $this->m_aImageSize[1]; $y += rand( 3, 7 ) )
               imagesetpixel( $this->m_oImage, $x, $y, $oColor );
       
       // Random Diagonal Lines
       for( $x = 0; $x < $this->m_aImageSize[0]; $x += rand( 15, 25 ) )
           imageline( $this->m_oImage, $x, 0, $x + rand( -50, 50 ), $this->m_aImageSize[1], $oColor );

       for( $y = 0; $y < $this->m_aImageSize[1]; $y += rand( 15, 25 ) )
           imageline( $this->m_oImage, 0, $y, $this->m_aImageSize[0], $y + rand( -50, 50 ), $oColor );

       return;
   }

   function WriteTTF( $iLocX, $iLocY, $iAngle, $szText )
   {
       $oColor = imagecolorallocate( $this->m_oImage, 255, 255, 255 );
       imagettftext( $this->m_oImage, $this->m_iFontSize, $iAngle, $iLocX, $iLocY, $oColor, $this->m_szFontFace, $szText );
   }
}
?>


Now, that class uses a True-Type font, which you can find in your c:\windows\fonts\ directory, but it should be placed in your web server where the script can access it..

Next, you will want to output that image.. something like:

CODE

// Create Turing Test Object
$oTuringTest = new TuringImage();
$oTuringTest->GenerateKey( 5 );  // Length of Key (5)

// Store key in sessions for later comparison
$_SESSION['SECURITY_KEY'] = $oTuringTest->GetKey();

// Set Content Type to GIF with NoCache
header( 'Content-type: image/gif' );
header( 'Expires: ' . gmdate('D, d M Y H:i:s') . 'GMT' );
header( 'Cache-control: no-cache' );

// Output Image
$oTuringTest->Create();


Now, all you need to do, is create a form that will allow the user to enter the text they see, and then submit that form back to one of your PHP pages, where you can then get the Posted Form variable, and compare it with the session value.. If it is correct, well, you know what to do!!

I hope that helps!
Go to the top of the page
 
+Quote Post
saga
post Sep 27 2005, 03:13 PM
Post #3


Premium Member
********

Group: Members
Posts: 165
Joined: 12-September 05
Member No.: 11,777



tnx for the code, its a great help... coz i dont have the time and resources to study the use of PHP in generating images..

tanx...
Go to the top of the page
 
+Quote Post
wariorpk
post Sep 27 2005, 07:03 PM
Post #4


Privileged Member
*********

Group: Members
Posts: 661
Joined: 18-April 05
Member No.: 5,852



Nice code I have always wondered how people got that to work. This is a great feature that is a must have for any site that lets you register for it.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [Code] - Shout Box(4)
  2. 1000 Free Psd Icon Images(10)
  3. Asp - Code Generator Wizard(0)
  4. I Have A Souce Code And I Was Wondering(2)
  5. Great Background Images(2)
  6. Great Background Images(1)
  7. Pre Load Images(12)
  8. Html Code Problem(7)
  9. Oscommerce Images?(4)
  10. View Souce Code(8)
  11. Phpbb And Mysql Relations?(2)
  12. Hoverbox Image Gallery(1)
  13. Best Way For Role-over Images?(2)
  14. Getting Flash Images On A Site(1)
  15. Forum Rpgs(1)
  1. How Do I Learn Web Design?(48)
  2. Almost There(8)
  3. Is There An Xbox Live Gamertag Code To Shw The Gamercard On A Website?(1)
  4. Target Links To A Div Layer(22)
  5. How Do I Code A Design?(6)
  6. Web Design Code(3)


 



- Lo-Fi Version Time is now: 11th October 2008 - 12:14 AM