Jump to content

Security Code Question


prcollin

Recommended Posts

Have mine I made:

<?php
/* makeimg.php v1.00
** Written by Ivan Oliver (11-Jun-2007)
*******************************************************************************/
  session_start();
  $imgWidth=130;
  $imgHeight=34;
  $chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
  $strText='';
  for ($i=1;$i<7;$i++) {$strText.=substr($chars,mt_rand(0,strlen($chars)-1),1);}
  $_SESSION['vercode']=md5($strText);
  header("Content-type: image/png");
  //$img=imagecreatetruecolor($imgWidth,$imgHeight); //22
  $img=imagecreatefrompng('gfx/codebg.png');
  $colBG=imagecolorallocate($img,0x11,0x11,0x11);
  $colFG=imagecolorallocate($img,255,255,255);
  for ($i=0;$i<strlen($strText);$i++) {
    $colFG=imagecolorallocate($img,mt_rand(50,255),mt_rand(50,255),mt_rand(50,255));
    imagettftext($img,20,mt_rand(-40,40),10+($i*20),27,$colFG,'fonts/times.ttf',substr($strText,$i,1));
  }
  imagepng($img);
  imagedestroy($img);
?>

Link to comment
Share on other sites

btw... here it is in action:

 

makeimg.php

 

Refresh the page to see it change.

 

EDIT: Forgot to mention that $chars has the character allowed in the code. Note that I removed some letters like lower case "L" and capital "O" to prevent them being confused with the numbers.

 

You'll need to upload a TrueType font file (TTF) to the server (in thisd case, Times.

Link to comment
Share on other sites

Yes, upload one from C:\WINDOWS\Fonts\ or C:\WINNT\Fonts\

 

Just upload it in binary mode and be sure to point the PHP script to the right place.

 

The script generates a PNG file for maximum quality with the image.

 

No security risk - all it is is just a data file containg font information.

Link to comment
Share on other sites

Have mine I made:

<?php
/* makeimg.php v1.00
** Written by Ivan Oliver (11-Jun-2007)
*******************************************************************************/
  session_start();
  $imgWidth=130;
  $imgHeight=34;
  $chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
  $strText='';
  for ($i=1;$i<7;$i++) {$strText.=substr($chars,mt_rand(0,strlen($chars)-1),1);}
  $_SESSION['vercode']=md5($strText);
  header("Content-type: image/png");
  //$img=imagecreatetruecolor($imgWidth,$imgHeight); //22
  $img=imagecreatefrompng('gfx/codebg.png');
  $colBG=imagecolorallocate($img,0x11,0x11,0x11);
  $colFG=imagecolorallocate($img,255,255,255);
  for ($i=0;$i<strlen($strText);$i++) {
    $colFG=imagecolorallocate($img,mt_rand(50,255),mt_rand(50,255),mt_rand(50,255));
    imagettftext($img,20,mt_rand(-40,40),10+($i*20),27,$colFG,'fonts/times.ttf',substr($strText,$i,1));
  }
  imagepng($img);
  imagedestroy($img);
?>

 

Thanks that saves me the programming time to figure out how to code it then writing it lol.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.