Jump to content
xisto Community
saga

Activation Code Images, How? need help with activation code images

Recommended Posts

hi everbody,I am creating this website for an online game KHAN which is of course hosted by Xisto.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? :ph34r:it is basically like here in Xisto 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 :D

Share this post


Link to post
Share on other sites

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:

<?phpclass 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:

// 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 NoCacheheader( '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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.