PHP
  Home arrow PHP arrow Page 2 - Security Images in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Security Images in PHP
By: Nathan Rohler
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 109
    2004-09-08


    Table of Contents:
  • Security Images in PHP
  • Getting Started -- Securityimage.php
  • Set Other Text Variables
  • Code for securityimage.php
  • Creating the Sign-up Demo -- Signupdemo.php
  • Form Handler Script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Security Images in PHP - Getting Started -- Securityimage.php
    ( Page 2 of 6 )

    The first page to create is the page which will generate the security images, securityimage.php. First, we need to open the PHP block and determine if we can use refid in the querystring; otherwise, we generate a unique one ourselves.

    <?php
    //Generate Reference ID
    if (isset($HTTP_GET_VARS["refid"]) && $HTTP_GET_VARS["refid"]!="") {
       $referenceid = stripslashes($HTTP_GET_VARS["refid"]);
    } else {
       $referenceid = md5(mktime()*rand());
    }

    Now, we must select a font to use. For this demo, we will use Century, because it is easy to distinguish between zeroes and o's, and because it is a serif font, it is harder for a computer to comprehend. You will need to set the path to the font, reflecting what OS you are using and where the fonts folder is.

    //Select Font
    $font = "C:\WINDOWS\Fonts\Century.ttf";

    Next, we will randomly select one of the three backgrounds (from the included files). Using one of these files, we initialize a new image identifier $im, representing the background image, using ImageCreateFromPNG. If you want more variety, you can create more backgrounds (must be PNG format).

    //Select random background image
    $bgurl = rand(1, 3);
    $im = ImageCreateFromPNG("images/bg".$bgurl.".png");

    After this, we will generate a random string. To do this, we first create an array of characters to use. Then, we specify a length for the text to be generated. For this demonstration, we will use 8, but you can change it to any length you wish. Finally, we create an empty variable, then randomly fill it with characters in a loop.

    //Generate the random string
    $chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G",
    "h","H","i","I","j","J","k",
    "K","l","L","m","M","n","N","o","O","p","P","q","Q","r",
    "R","s","S","t","T","u","U","v",
    "V","w","W","x","X","y","Y","z","Z","1","2","3","4","5",
    "6","7","8","9");
    $length = 8;
    $textstr = "";
    for ($i=0; $i<$length; $i++) {
       $textstr .= $chars[rand(0, count($chars)-1)];
    }



     
     
    >>> More PHP Articles          >>> More By Nathan Rohler
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek