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);
?>

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.