Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit 404f89a8043275f48cb841507899daadd2647449 0 parents
@dapphp authored
Showing with 18,051 additions and 0 deletions.
  1. BIN  AHGBold.ttf
  2. +458 −0 LICENSE.txt
  3. +12 −0 README.FONT.txt
  4. +88 −0 README.txt
  5. BIN  audio/0.mp3
  6. BIN  audio/0.wav
  7. BIN  audio/1.mp3
  8. BIN  audio/1.wav
  9. BIN  audio/2.mp3
  10. BIN  audio/2.wav
  11. BIN  audio/3.mp3
  12. BIN  audio/3.wav
  13. BIN  audio/4.mp3
  14. BIN  audio/4.wav
  15. BIN  audio/5.mp3
  16. BIN  audio/5.wav
  17. BIN  audio/6.mp3
  18. BIN  audio/6.wav
  19. BIN  audio/7.mp3
  20. BIN  audio/7.wav
  21. BIN  audio/8.mp3
  22. BIN  audio/8.wav
  23. BIN  audio/9.mp3
  24. BIN  audio/9.wav
  25. BIN  audio/A.mp3
  26. BIN  audio/A.wav
  27. BIN  audio/B.mp3
  28. BIN  audio/B.wav
  29. BIN  audio/C.mp3
  30. BIN  audio/C.wav
  31. BIN  audio/D.mp3
  32. BIN  audio/D.wav
  33. BIN  audio/E.mp3
  34. BIN  audio/E.wav
  35. BIN  audio/F.mp3
  36. BIN  audio/F.wav
  37. BIN  audio/G.mp3
  38. BIN  audio/G.wav
  39. BIN  audio/H.mp3
  40. BIN  audio/H.wav
  41. BIN  audio/I.mp3
  42. BIN  audio/I.wav
  43. BIN  audio/J.mp3
  44. BIN  audio/J.wav
  45. BIN  audio/K.mp3
  46. BIN  audio/K.wav
  47. BIN  audio/L.mp3
  48. BIN  audio/L.wav
  49. BIN  audio/M.mp3
  50. BIN  audio/M.wav
  51. BIN  audio/N.mp3
  52. BIN  audio/N.wav
  53. BIN  audio/O.mp3
  54. BIN  audio/O.wav
  55. BIN  audio/P.mp3
  56. BIN  audio/P.wav
  57. BIN  audio/Q.mp3
  58. BIN  audio/Q.wav
  59. BIN  audio/R.mp3
  60. BIN  audio/R.wav
  61. BIN  audio/S.mp3
  62. BIN  audio/S.wav
  63. BIN  audio/T.mp3
  64. BIN  audio/T.wav
  65. BIN  audio/U.mp3
  66. BIN  audio/U.wav
  67. BIN  audio/V.mp3
  68. BIN  audio/V.wav
  69. BIN  audio/W.mp3
  70. BIN  audio/W.wav
  71. BIN  audio/X.mp3
  72. BIN  audio/X.wav
  73. BIN  audio/Y.mp3
  74. BIN  audio/Y.wav
  75. BIN  audio/Z.mp3
  76. BIN  audio/Z.wav
  77. BIN  backgrounds/bg3.jpg
  78. BIN  backgrounds/bg4.jpg
  79. BIN  backgrounds/bg5.jpg
  80. BIN  backgrounds/bg6.png
  81. +1 −0  database/.htaccess
  82. +1 −0  database/index.html
  83. BIN  database/securimage.sqlite
  84. +71 −0 example_form.php
  85. BIN  gdfonts/automatic.gdf
  86. BIN  images/audio_icon.gif
  87. BIN  images/refresh.gif
  88. +1,584 −0 securimage.php
  89. +43 −0 securimage_play.php
  90. BIN  securimage_play.swf
  91. +55 −0 securimage_show.php
  92. +64 −0 securimage_show_example.php
  93. +55 −0 securimage_show_example2.php
  94. +15,619 −0 words/words.txt
BIN  AHGBold.ttf
Binary file not shown
458 LICENSE.txt
@@ -0,0 +1,458 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
12 README.FONT.txt
@@ -0,0 +1,12 @@
+AHGBold.ttf is used by Securimage under the following license:
+
+Alte Haas Grotesk is a typeface that look like an helvetica printed in an old Muller-Brockmann Book.
+
+These fonts are freeware and can be distributed as long as they are
+together with this text file.
+
+I would appreciate very much to see what you have done with it anyway.
+
+yann le coroller
+www.yannlecoroller.com
+yann@lecoroller.com
88 README.txt
@@ -0,0 +1,88 @@
+NAME:
+
+ Securimage - A PHP class for creating and managing form CAPTCHA images
+
+VERSION: 2.0 BETA
+
+AUTHOR:
+
+ Drew Phillips <drew@drew-phillips.com>
+
+DOWNLOAD:
+
+ The latest version can always be
+ found at http://www.phpcaptcha.org
+
+DOCUMENTATION:
+
+ Online documentation of the class, methods, and variables can
+ be found at http://www.phpcaptcha.org/Securimage_Docs/
+
+REQUIREMENTS:
+ PHP 4.3.0
+ GD 2.0
+ FreeType (recommended, required for TTF support)
+
+SYNOPSIS:
+
+ require_once 'securimage.php';
+
+ $image = new Securimage();
+
+ $image->show();
+
+ // Code Validation
+
+ $image = new Securimage();
+ if ($image->check($_POST['code']) == true) {
+ echo "Correct!";
+ } else {
+ echo "Sorry, wrong code.";
+ }
+
+DESCRIPTION:
+
+ What is Securimage?
+
+ Securimage is a PHP class that is used to generate and validate CAPTCHA images.
+ The classes uses an existing PHP session or creates its own if none is found to store the
+ CAPTCHA code. Variables within the class are used to control the style and display of the image.
+ The class supports TTF fonts and effects for strengthening the security of the image.
+ If TTF support is not available, GD fonts can be used as well, but certain options such as
+ transparent text and angled letters cannot be used.
+
+
+COPYRIGHT:
+ Copyright (c) 2009 Drew Phillips. All rights reserved.
+ This software is released under the GNU Lesser General Public License.
+
+ -----------------------------------------------------------------------------
+ Flash code created for Securimage by Douglas Walsh (www.douglaswalsh.net)
+ Many thanks for releasing this to the project!
+
+ ------------------------------------------------------------------------------
+ Portions of Securimage contain code from Han-Kwang Nienhuys' PHP captcha
+
+ Han-Kwang Nienhuys' PHP captcha
+ Copyright June 2007
+
+ This copyright message and attribution must be preserved upon
+ modification. Redistribution under other licenses is expressly allowed.
+ Other licenses include GPL 2 or higher, BSD, and non-free licenses.
+ The original, unrestricted version can be obtained from
+ http://www.lagom.nl/linux/hkcaptcha/
+
+ -------------------------------------------------------------------------------
+ AHGBold.ttf (AlteHaasGroteskBold.ttf) font was created by Yann Le Coroller and is distributed as freeware
+
+ Alte Haas Grotesk is a typeface that look like an helvetica printed in an old Muller-Brockmann Book.
+
+ These fonts are freeware and can be distributed as long as they are
+ together with this text file.
+
+ I would appreciate very much to see what you have done with it anyway.
+
+ yann le coroller
+ www.yannlecoroller.com
+ yann@lecoroller.com
+
BIN  audio/0.mp3
Binary file not shown
BIN  audio/0.wav
Binary file not shown
BIN  audio/1.mp3
Binary file not shown
BIN  audio/1.wav
Binary file not shown
BIN  audio/2.mp3
Binary file not shown
BIN  audio/2.wav
Binary file not shown
BIN  audio/3.mp3
Binary file not shown
BIN  audio/3.wav
Binary file not shown
BIN  audio/4.mp3
Binary file not shown
BIN  audio/4.wav
Binary file not shown
BIN  audio/5.mp3
Binary file not shown
BIN  audio/5.wav
Binary file not shown
BIN  audio/6.mp3
Binary file not shown
BIN  audio/6.wav
Binary file not shown
BIN  audio/7.mp3
Binary file not shown
BIN  audio/7.wav
Binary file not shown
BIN  audio/8.mp3
Binary file not shown
BIN  audio/8.wav
Binary file not shown
BIN  audio/9.mp3
Binary file not shown
BIN  audio/9.wav
Binary file not shown
BIN  audio/A.mp3
Binary file not shown
BIN  audio/A.wav
Binary file not shown
BIN  audio/B.mp3
Binary file not shown
BIN  audio/B.wav
Binary file not shown
BIN  audio/C.mp3
Binary file not shown
BIN  audio/C.wav
Binary file not shown
BIN  audio/D.mp3
Binary file not shown
BIN  audio/D.wav
Binary file not shown
BIN  audio/E.mp3
Binary file not shown
BIN  audio/E.wav
Binary file not shown
BIN  audio/F.mp3
Binary file not shown
BIN  audio/F.wav
Binary file not shown
BIN  audio/G.mp3
Binary file not shown
BIN  audio/G.wav
Binary file not shown
BIN  audio/H.mp3
Binary file not shown
BIN  audio/H.wav
Binary file not shown
BIN  audio/I.mp3
Binary file not shown
BIN  audio/I.wav
Binary file not shown
BIN  audio/J.mp3
Binary file not shown
BIN  audio/J.wav
Binary file not shown
BIN  audio/K.mp3
Binary file not shown
BIN  audio/K.wav
Binary file not shown
BIN  audio/L.mp3
Binary file not shown
BIN  audio/L.wav
Binary file not shown
BIN  audio/M.mp3
Binary file not shown
BIN  audio/M.wav
Binary file not shown
BIN  audio/N.mp3
Binary file not shown
BIN  audio/N.wav
Binary file not shown
BIN  audio/O.mp3
Binary file not shown
BIN  audio/O.wav
Binary file not shown
BIN  audio/P.mp3
Binary file not shown
BIN  audio/P.wav
Binary file not shown
BIN  audio/Q.mp3
Binary file not shown
BIN  audio/Q.wav
Binary file not shown
BIN  audio/R.mp3
Binary file not shown
BIN  audio/R.wav
Binary file not shown
BIN  audio/S.mp3
Binary file not shown
BIN  audio/S.wav
Binary file not shown
BIN  audio/T.mp3
Binary file not shown
BIN  audio/T.wav
Binary file not shown
BIN  audio/U.mp3
Binary file not shown
BIN  audio/U.wav
Binary file not shown
BIN  audio/V.mp3
Binary file not shown
BIN  audio/V.wav
Binary file not shown
BIN  audio/W.mp3
Binary file not shown
BIN  audio/W.wav
Binary file not shown
BIN  audio/X.mp3
Binary file not shown
BIN  audio/X.wav
Binary file not shown
BIN  audio/Y.mp3
Binary file not shown
BIN  audio/Y.wav
Binary file not shown
BIN  audio/Z.mp3
Binary file not shown
BIN  audio/Z.wav
Binary file not shown
BIN  backgrounds/bg3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  backgrounds/bg4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  backgrounds/bg5.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  backgrounds/bg6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1  database/.htaccess
@@ -0,0 +1 @@
+deny from all
1  database/index.html
@@ -0,0 +1 @@
+
BIN  database/securimage.sqlite
Binary file not shown
71 example_form.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Project: Securimage: A PHP class for creating and managing form CAPTCHA images<br />
+ * File: securimage.php<br />
+ * URL: www.phpcaptcha.org
+ */
+
+
+session_start(); // Start the session where the code will be stored.
+
+?>
+<html>
+<head>
+ <title>Securimage Test Form</title>
+</head>
+
+<body>
+
+<?php
+if (empty($_POST)) { ?>
+<form method="POST">
+Username:<br />
+<input type="text" name="username" /><br />
+Password:<br />
+<input type="text" name="password" /><br /><br />
+
+<div style="width: 430px; float: left; height: 90px">
+ <img id="siimage" align="left" style="padding-right: 5px; border: 0" src="securimage_show.php?sid=<?php echo md5(time()) ?>" />
+
+ <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
+ <param name="allowScriptAccess" value="sameDomain" />
+ <param name="allowFullScreen" value="false" />
+ <param name="movie" value="securimage_play.swf?audio=securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" />
+ <param name="quality" value="high" />
+
+ <param name="bgcolor" value="#ffffff" />
+ <embed src="securimage_play.swf?audio=securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" quality="high" bgcolor="#ffffff" width="19" height="19" name="SecurImage_as3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
+ </object>
+
+ <br />
+
+ <!-- pass a session id to the query string of the script to prevent ie caching -->
+ <a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = 'securimage_show.php?sid=' + Math.random(); return false"><img src="images/refresh.gif" alt="Reload Image" border="0" onclick="this.blur()" align="bottom" /></a>
+</div>
+<div style="clear: both"></div>
+Code:<br />
+
+<!-- NOTE: the "name" attribute is "code" so that $img->check($_POST['code']) will check the submitted form field -->
+<input type="text" name="code" size="12" /><br /><br />
+
+<input type="submit" value="Submit Form" />
+</form>
+
+<?php
+} else { //form is posted
+ include("securimage.php");
+ $img = new Securimage();
+ $valid = $img->check($_POST['code']);
+
+ if($valid == true) {
+ echo "<center>Thanks, you entered the correct code.<br />Click <a href=\"{$_SERVER['PHP_SELF']}\">here</a> to go back.</center>";
+ } else {
+ echo "<center>Sorry, the code you entered was invalid. <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>";
+ }
+}
+
+?>
+
+</body>
+</html>
BIN  gdfonts/automatic.gdf
Binary file not shown
BIN  images/audio_icon.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  images/refresh.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,584 securimage.php
@@ -0,0 +1,1584 @@
+<?php
+
+/**
+ * Project: Securimage: A PHP class for creating and managing form CAPTCHA images<br />
+ * File: securimage.php<br />
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.<br /><br />
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.<br /><br />
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br /><br />
+ *
+ * Any modifications to the library should be indicated clearly in the source code
+ * to inform users that the changes are not a part of the original software.<br /><br />
+ *
+ * If you found this script useful, please take a quick moment to rate it.<br />
+ * http://www.hotscripts.com/rate/49400.html Thanks.
+ *
+ * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA
+ * @link http://www.phpcaptcha.org/latest.zip Download Latest Version
+ * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
+ * @copyright 2009 Drew Phillips
+ * @author Drew Phillips <drew@drew-phillips.com>
+ * @version 2.0.1 BETA (December 6th, 2009)
+ * @package Securimage
+ *
+ */
+
+/**
+ ChangeLog
+
+ 2.0.1
+ - Add support for browsers with cookies disabled (requires php5, sqlite) maps users to md5 hashed ip addresses and md5 hashed codes for security
+ - Add fallback to gd fonts if ttf support is not enabled or font file not found (Mike Challis http://www.642weather.com/weather/scripts.php)
+ - Check for previous definition of image type constants (Mike Challis)
+ - Fix mime type settings for audio output
+ - Fixed color allocation issues with multiple colors and background images, consolidate allocation to one function
+ - Ability to let codes expire after a given length of time
+ - Allow HTML color codes to be passed to Securimage_Color (suggested by Mike Challis)
+
+ 2.0.0
+ - Add mathematical distortion to characters (using code from HKCaptcha)
+ - Improved session support
+ - Added Securimage_Color class for easier color definitions
+ - Add distortion to audio output to prevent binary comparison attack (proposed by Sven "SavageTiger" Hagemann [insecurity.nl])
+ - Flash button to stream mp3 audio (Douglas Walsh www.douglaswalsh.net)
+ - Audio output is mp3 format by default
+ - Change font to AlteHaasGrotesk by yann le coroller
+ - Some code cleanup
+
+ 1.0.4 (unreleased)
+ - Ability to output audible codes in mp3 format to stream from flash
+
+ 1.0.3.1
+ - Error reading from wordlist in some cases caused words to be cut off 1 letter short
+
+ 1.0.3
+ - Removed shadow_text from code which could cause an undefined property error due to removal from previous version
+
+ 1.0.2
+ - Audible CAPTCHA Code wav files
+ - Create codes from a word list instead of random strings
+
+ 1.0
+ - Added the ability to use a selected character set, rather than a-z0-9 only.
+ - Added the multi-color text option to use different colors for each letter.
+ - Switched to automatic session handling instead of using files for code storage
+ - Added GD Font support if ttf support is not available. Can use internal GD fonts or load new ones.
+ - Added the ability to set line thickness
+ - Added option for drawing arced lines over letters
+ - Added ability to choose image type for output
+
+ */
+
+/**
+ * Output images in JPEG format
+ */
+if (!defined('SI_IMAGE_JPEG'))
+ define('SI_IMAGE_JPEG', 1);
+/**
+ * Output images in PNG format
+ */
+if (!defined('SI_IMAGE_PNG'))
+ define('SI_IMAGE_PNG', 2);
+/**
+ * Output images in GIF format (not recommended)
+ * Must have GD >= 2.0.28!
+ */
+if (!defined('SI_IMAGE_GIF'))
+ define('SI_IMAGE_GIF', 3);
+
+/**
+ * Securimage CAPTCHA Class.
+ *
+ * @package Securimage
+ * @subpackage classes
+ *
+ */
+class Securimage {
+
+ /**
+ * The desired width of the CAPTCHA image.
+ *
+ * @var int
+ */
+ var $image_width;
+
+ /**
+ * The desired width of the CAPTCHA image.
+ *
+ * @var int
+ */
+ var $image_height;
+
+ /**
+ * The image format for output.<br />
+ * Valid options: SI_IMAGE_PNG, SI_IMAGE_JPG, SI_IMAGE_GIF
+ *
+ * @var int
+ */
+ var $image_type;
+
+ /**
+ * The length of the code to generate.
+ *
+ * @var int
+ */
+ var $code_length;
+
+ /**
+ * The character set for individual characters in the image.<br />
+ * Letters are converted to uppercase.<br />
+ * The font must support the letters or there may be problematic substitutions.
+ *
+ * @var string
+ */
+ var $charset;
+
+ /**
+ * Create codes using this word list
+ *
+ * @var string The path to the word list to use for creating CAPTCHA codes
+ */
+ var $wordlist_file;
+
+ /**
+ * Use wordlist of not
+ *
+ * @var bool true to use wordlist file, false to use random code
+ */
+ var $use_wordlist = false;
+
+ /**
+ * Note: Use of GD fonts is not recommended as many distortion features are not available<br />
+ * The GD font to use.<br />
+ * Internal gd fonts can be loaded by their number.<br />
+ * Alternatively, a file path can be given and the font will be loaded from file.
+ *
+ * @var mixed
+ */
+ var $gd_font_file;
+
+ /**
+ * The approximate size of the font in pixels.<br />
+ * This does not control the size of the font because that is determined by the GD font itself.<br />
+ * This is used to aid the calculations of positioning used by this class.<br />
+ *
+ * @var int
+ */
+ var $gd_font_size;
+
+ /**
+ * Use a gd font instead of TTF
+ *
+ * @var bool true for gd font, false for TTF
+ */
+ var $use_gd_font;
+
+ // Note: These font options below do not apply if you set $use_gd_font to true with the exception of $text_color
+
+ /**
+ * The path to the TTF font file to load.
+ *
+ * @var string
+ */
+ var $ttf_file;
+
+ /**
+ * How much to distort image, higher = more distortion.<br />
+ * Distortion is only available when using TTF fonts.<br />
+ *
+ * @var float
+ */
+ var $perturbation;
+
+ /**
+ * The minimum angle in degrees, with 0 degrees being left-to-right reading text.<br />
+ * Higher values represent a counter-clockwise rotation.<br />
+ * For example, a value of 90 would result in bottom-to-top reading text.<br />
+ * This value along with maximum angle distance do not need to be very high with perturbation
+ *
+ * @var int
+ */
+ var $text_angle_minimum;
+
+ /**
+ * The minimum angle in degrees, with 0 degrees being left-to-right reading text.<br />
+ * Higher values represent a counter-clockwise rotation.<br />
+ * For example, a value of 90 would result in bottom-to-top reading text.
+ *
+ * @var int
+ */
+ var $text_angle_maximum;
+
+ /**
+ * The X-Position on the image where letter drawing will begin.<br />
+ * This value is in pixels from the left side of the image.
+ *
+ * @var int
+ * @deprecated 2.0
+ */
+ var $text_x_start;
+
+ /**
+ * The background color for the image as a Securimage_Color.<br />
+ *
+ * @var Securimage_Color
+ */
+ var $image_bg_color;
+
+ /**
+ * Scan this directory for gif, jpg, and png files to use as background images.<br />
+ * A random image file will be picked each time.<br />
+ * Change from null to the full path to your directory.<br />
+ * i.e. var $background_directory = $_SERVER['DOCUMENT_ROOT'] . '/securimage/backgrounds';
+ * Make sure not to pass a background image to the show function, otherwise this directive is ignored.
+ *
+ * @var string
+ */
+ var $background_directory = null; //'./backgrounds';
+
+ /**
+ * The text color to use for drawing characters as a Securimage_Color.<br />
+ * This value is ignored if $use_multi_text is set to true.<br />
+ * Make sure this contrasts well with the background color or image.<br />
+ *
+ * @see Securimage::$use_multi_text
+ * @var Securimage_Color
+ */
+ var $text_color;
+
+ /**
+ * Set to true to use multiple colors for each character.
+ *
+ * @see Securimage::$multi_text_color
+ * @var boolean
+ */
+ var $use_multi_text;
+
+ /**
+ * Array of Securimage_Colors which will be randomly selected for each letter.<br />
+ *
+ * @var array
+ */
+ var $multi_text_color;
+
+ /**
+ * Set to true to make the characters appear transparent.
+ *
+ * @see Securimage::$text_transparency_percentage
+ * @var boolean
+ */
+ var $use_transparent_text;
+
+ /**
+ * The percentage of transparency, 0 to 100.<br />
+ * A value of 0 is completely opaque, 100 is completely transparent (invisble)
+ *
+ * @see Securimage::$use_transparent_text
+ * @var int
+ */
+ var $text_transparency_percentage;
+
+
+ // Line options
+ /**
+ * Draw vertical and horizontal lines on the image.
+ *
+ * @see Securimage::$line_color
+ * @see Securimage::$draw_lines_over_text
+ * @var boolean
+ */
+ var $num_lines;
+
+ /**
+ * Color of lines drawn over text
+ *
+ * @var string
+ */
+ var $line_color;
+
+ /**
+ * Draw the lines over the text.<br />
+ * If fales lines will be drawn before putting the text on the image.
+ *
+ * @var boolean
+ */
+ var $draw_lines_over_text;
+
+ /**
+ * Text to write at the bottom corner of captcha image
+ *
+ * @since 2.0
+ * @var string Signature text
+ */
+ var $image_signature;
+
+ /**
+ * Color to use for writing signature text
+ *
+ * @since 2.0
+ * @var Securimage_Color
+ */
+ var $signature_color;
+
+ /**
+ * Full path to the WAV files to use to make the audio files, include trailing /.<br />
+ * Name Files [A-Z0-9].wav
+ *
+ * @since 1.0.1
+ * @var string
+ */
+ var $audio_path;
+
+ /**
+ * Type of audio file to generate (mp3 or wav)
+ *
+ * @var string
+ */
+ var $audio_format;
+
+ /**
+ * The session name to use if not the default. Blank for none
+ *
+ * @see http://php.net/session_name
+ * @since 2.0
+ * @var string
+ */
+ var $session_name = '';
+
+ /**
+ * The amount of time in seconds that a code remains valid.<br />
+ * Any code older than this number will be considered invalid even if entered correctly.<br />
+ * Any non-numeric or value less than 1 disables this functionality.
+ *
+ * @var int
+ */
+ var $expiry_time;
+
+ /**
+ * Path to the file to use for storing codes for users.<br />
+ * THIS FILE MUST ABSOLUTELY NOT BE ACCESSIBLE FROM A WEB BROWSER!!<br />
+ * Put this file in a directory below the web root or one that is restricted (i.e. an apache .htaccess file with deny from all)<br />
+ * If you cannot meet those requirements your forms may not be completely protected.<br />
+ * You could obscure the database file name but this is also not recommended.
+ *
+ * @var string
+ */
+ var $sqlite_database;
+
+ /**
+ * Use an SQLite database for storing codes as a backup to sessions.<br />
+ * Note: Sessions will still be used
+ */
+ var $use_sqlite_db;
+
+
+ //END USER CONFIGURATION
+ //There should be no need to edit below unless you really know what you are doing.
+
+ /**
+ * The gd image resource.
+ *
+ * @access private
+ * @var resource
+ */
+ var $im;
+
+ /**
+ * Temporary image for rendering
+ *
+ * @access private
+ * @var resource
+ */
+ var $tmpimg;
+
+ /**
+ * Internal scale factor for anti-alias @hkcaptcha
+ *
+ * @access private
+ * @since 2.0
+ * @var int
+ */
+ var $iscale; // internal scale factor for anti-alias @hkcaptcha
+
+ /**
+ * The background image resource
+ *
+ * @access private
+ * @var resource
+ */
+ var $bgimg;
+
+ /**
+ * The code generated by the script
+ *
+ * @access private
+ * @var string
+ */
+ var $code;
+
+ /**
+ * The code that was entered by the user
+ *
+ * @access private
+ * @var string
+ */
+ var $code_entered;
+
+ /**
+ * Whether or not the correct code was entered
+ *
+ * @access private
+ * @var boolean
+ */
+ var $correct_code;
+
+ /**
+ * Handle to SQLite database
+ *
+ * @access private
+ * @var resource
+ */
+ var $sqlite_handle;
+
+ /**
+ * Color resource for image line color
+ *
+ * @access private
+ * @var int
+ */
+ var $gdlinecolor;
+
+ /**
+ * Array of colors for multi colored codes
+ *
+ * @access private
+ * @var array
+ */
+ var $gdmulticolor;
+
+ /**
+ * Color resource for image font color
+ *
+ * @access private
+ * @var int
+ */
+ var $gdtextcolor;
+
+ /**
+ * Color resource for image signature color
+ *
+ * @access private
+ * @var int
+ */
+ var $gdsignaturecolor;
+
+ /**
+ * Color resource for image background color
+ *
+ * @access private
+ * @var int
+ */
+ var $gdbgcolor;
+
+
+ /**
+ * Class constructor.<br />
+ * Because the class uses sessions, this will attempt to start a session if there is no previous one.<br />
+ * If you do not start a session before calling the class, the constructor must be called before any
+ * output is sent to the browser.
+ *
+ * <code>
+ * $securimage = new Securimage();
+ * </code>
+ *
+ */
+ function Securimage()
+ {
+ // Initialize session or attach to existing
+ if ( session_id() == '' ) { // no session has been started yet, which is needed for validation
+ if (trim($this->session_name) != '') {
+ session_name($this->session_name); // set session name if provided
+ }
+ session_start();
+ }
+
+ // Set Default Values
+ $this->image_width = 230;
+ $this->image_height = 80;
+ $this->image_type = SI_IMAGE_PNG;
+
+ $this->code_length = 6;
+ $this->charset = 'ABCDEFGHKLMNPRSTUVWYZabcdefghklmnprstuvwyz23456789';
+ $this->wordlist_file = './words/words.txt';
+ $this->use_wordlist = false;
+
+ $this->gd_font_file = 'gdfonts/automatic.gdf';
+ $this->use_gd_font = false;
+ $this->gd_font_size = 24;
+ $this->text_x_start = 15;
+
+ $this->ttf_file = './AHGBold.ttf';
+
+ $this->perturbation = 0.75;
+ $this->iscale = 5;
+ $this->text_angle_minimum = 0;
+ $this->text_angle_maximum = 0;
+
+ $this->image_bg_color = new Securimage_Color(0xff, 0xff, 0xff);
+ $this->text_color = new Securimage_Color(0x3d, 0x3d, 0x3d);
+ $this->multi_text_color = array(new Securimage_Color(0x0, 0x20, 0xCC),
+ new Securimage_Color(0x0, 0x30, 0xEE),
+ new Securimage_color(0x0, 0x40, 0xCC),
+ new Securimage_Color(0x0, 0x50, 0xEE),
+ new Securimage_Color(0x0, 0x60, 0xCC));
+ $this->use_multi_text = false;
+
+ $this->use_transparent_text = false;
+ $this->text_transparency_percentage = 30;
+
+ $this->num_lines = 10;
+ $this->line_color = new Securimage_Color(0x3d, 0x3d, 0x3d);
+ $this->draw_lines_over_text = true;
+
+ $this->image_signature = '';
+ $this->signature_color = new Securimage_Color(0x20, 0x50, 0xCC);
+ $this->signature_font = './AHGBold.ttf';
+
+ $this->audio_path = './audio/';
+ $this->audio_format = 'mp3';
+ $this->session_name = '';
+ $this->expiry_time = 900;
+
+ $this->sqlite_database = 'database/securimage.sqlite';
+ $this->use_sqlite_db = false;
+
+ $this->sqlite_handle = false;
+ }
+
+ /**
+ * Generate a code and output the image to the browser.
+ *
+ * <code>
+ * <?php
+ * include 'securimage.php';
+ * $securimage = new Securimage();
+ * $securimage->show('bg.jpg');
+ * ?>
+ * </code>
+ *
+ * @param string $background_image The path to an image to use as the background for the CAPTCHA
+ */
+ function show($background_image = "")
+ {
+ if($background_image != "" && is_readable($background_image)) {
+ $this->bgimg = $background_image;
+ }
+
+ $this->doImage();
+ }
+
+ /**
+ * Validate the code entered by the user.
+ *
+ * <code>
+ * $code = $_POST['code'];
+ * if ($securimage->check($code) == false) {
+ * die("Sorry, the code entered did not match.");
+ * } else {
+ * $valid = true;
+ * }
+ * </code>
+ * @param string $code The code the user entered
+ * @return boolean true if the code was correct, false if not
+ */
+ function check($code)
+ {
+ $this->code_entered = $code;
+ $this->validate();
+ return $this->correct_code;
+ }
+
+ /**
+ * Output audio file with HTTP headers to browser
+ *
+ * <code>
+ * $sound = new Securimage();
+ * $sound->audio_format = 'mp3';
+ * $sound->outputAudioFile();
+ * </code>
+ *
+ * @since 2.0
+ */
+ function outputAudioFile()
+ {
+ if (strtolower($this->audio_format) == 'wav') {
+ header('Content-type: audio/x-wav');
+ $ext = 'wav';
+ } else {
+ header('Content-type: audio/mpeg'); // default to mp3
+ $ext = 'mp3';
+ }
+
+ header("Content-Disposition: attachment; filename=\"securimage_audio.{$ext}\"");
+ header('Cache-Control: no-store, no-cache, must-revalidate');
+ header('Expires: Sun, 1 Jan 2000 12:00:00 GMT');
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
+
+ $audio = $this->getAudibleCode($ext);
+
+ header('Content-Length: ' . strlen($audio));
+
+ echo $audio;
+ exit;
+ }
+
+ /**
+ * Generate and output the image
+ *
+ * @access private
+ *
+ */
+ function doImage()
+ {
+ if ($this->use_gd_font == true) {
+ $this->iscale = 1;
+ }
+ if($this->use_transparent_text == true || $this->bgimg != "") {
+ $this->im = imagecreatetruecolor($this->image_width, $this->image_height);
+ $this->tmpimg = imagecreatetruecolor($this->image_width * $this->iscale, $this->image_height * $this->iscale);
+
+ } else { //no transparency
+ $this->im = imagecreate($this->image_width, $this->image_height);
+ $this->tmpimg = imagecreate($this->image_width * $this->iscale, $this->image_height * $this->iscale);
+ }
+
+ $this->allocateColors();
+ imagepalettecopy($this->tmpimg, $this->im);
+
+ $this->setBackground();
+
+ $this->createCode();
+
+ if (!$this->draw_lines_over_text && $this->num_lines > 0) $this->drawLines();
+
+ $this->drawWord();
+ if ($this->use_gd_font == false && is_readable($this->ttf_file)) $this->distortedCopy();
+
+ if ($this->draw_lines_over_text && $this->num_lines > 0) $this->drawLines();
+
+ if (trim($this->image_signature) != '') $this->addSignature();
+
+ $this->output();
+
+ }
+
+ /**
+ * Allocate all colors that will be used in the CAPTCHA image
+ *
+ * @since 2.0.1
+ * @access private
+ */
+ function allocateColors()
+ {
+ // allocate bg color first for imagecreate
+ $this->gdbgcolor = imagecolorallocate($this->im, $this->image_bg_color->r, $this->image_bg_color->g, $this->image_bg_color->b);
+
+ $alpha = intval($this->text_transparency_percentage / 100 * 127);
+
+ if ($this->use_transparent_text == true) {
+ $this->gdtextcolor = imagecolorallocatealpha($this->im, $this->text_color->r, $this->text_color->g, $this->text_color->b, $alpha);
+ $this->gdlinecolor = imagecolorallocatealpha($this->im, $this->line_color->r, $this->line_color->g, $this->line_color->b, $alpha);
+ } else {
+ $this->gdtextcolor = imagecolorallocate($this->im, $this->text_color->r, $this->text_color->g, $this->text_color->b);
+ $this->gdlinecolor = imagecolorallocate($this->im, $this->line_color->r, $this->line_color->g, $this->line_color->b);
+ }
+
+ $this->gdsignaturecolor = imagecolorallocate($this->im, $this->signature_color->r, $this->signature_color->g, $this->signature_color->b);
+
+ if ($this->use_multi_text == true) {
+ $this->gdmulticolor = array();
+
+ foreach($this->multi_text_color as $color) {
+ if ($this->use_transparent_text == true) {
+ $this->gdmulticolor[] = imagecolorallocatealpha($this->im, $color->r, $color->g, $color->b, $alpha);
+ } else {
+ $this->gdmulticolor[] = imagecolorallocate($this->im, $color->r, $color->g, $color->b);
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the background of the CAPTCHA image
+ *
+ * @access private
+ *
+ */
+ function setBackground()
+ {
+ imagefilledrectangle($this->im, 0, 0, $this->image_width * $this->iscale, $this->image_height * $this->iscale, $this->gdbgcolor);
+ imagefilledrectangle($this->tmpimg, 0, 0, $this->image_width * $this->iscale, $this->image_height * $this->iscale, $this->gdbgcolor);
+
+ if ($this->bgimg == '') {
+ if ($this->background_directory != null && is_dir($this->background_directory) && is_readable($this->background_directory)) {
+ $img = $this->getBackgroundFromDirectory();
+ if ($img != false) {
+ $this->bgimg = $img;
+ }
+ }
+ }
+
+ $dat = @getimagesize($this->bgimg);
+ if($dat == false) {
+ return;
+ }
+
+ switch($dat[2]) {
+ case 1: $newim = @imagecreatefromgif($this->bgimg); break;
+ case 2: $newim = @imagecreatefromjpeg($this->bgimg); break;
+ case 3: $newim = @imagecreatefrompng($this->bgimg); break;
+ case 15: $newim = @imagecreatefromwbmp($this->bgimg); break;
+ case 16: $newim = @imagecreatefromxbm($this->bgimg); break;
+ default: return;
+ }
+
+ if(!$newim) return;
+
+ imagecopyresized($this->im, $newim, 0, 0, 0, 0, $this->image_width, $this->image_height, imagesx($newim), imagesy($newim));
+ }
+
+ /**
+ * Return the full path to a random gif, jpg, or png from the background directory.
+ *
+ * @access private
+ * @see Securimage::$background_directory
+ * @return mixed false if none found, string $path if found
+ */
+ function getBackgroundFromDirectory()
+ {
+ $images = array();
+
+ if ($dh = opendir($this->background_directory)) {
+ while (($file = readdir($dh)) !== false) {
+ if (preg_match('/(jpg|gif|png)$/i', $file)) $images[] = $file;
+ }
+
+ closedir($dh);
+
+ if (sizeof($images) > 0) {
+ return rtrim($this->background_directory, '/') . '/' . $images[rand(0, sizeof($images)-1)];
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Draw random curvy lines over the image<br />
+ * Modified code from HKCaptcha
+ *
+ * @since 2.0
+ * @access private
+ *
+ */
+ function drawLines()
+ {
+ for ($line = 0; $line < $this->num_lines; ++$line) {
+ $x = $this->image_width * (1 + $line) / ($this->num_lines + 1);
+ $x += (0.5 - $this->frand()) * $this->image_width / $this->num_lines;
+ $y = rand($this->image_height * 0.1, $this->image_height * 0.9);
+
+ $theta = ($this->frand()-0.5) * M_PI * 0.7;
+ $w = $this->image_width;
+ $len = rand($w * 0.4, $w * 0.7);
+ $lwid = rand(0, 2);
+
+ $k = $this->frand() * 0.6 + 0.2;
+ $k = $k * $k * 0.5;
+ $phi = $this->frand() * 6.28;
+ $step = 0.5;
+ $dx = $step * cos($theta);
+ $dy = $step * sin($theta);
+ $n = $len / $step;
+ $amp = 1.5 * $this->frand() / ($k + 5.0 / $len);
+ $x0 = $x - 0.5 * $len * cos($theta);
+ $y0 = $y - 0.5 * $len * sin($theta);
+
+ $ldx = round(-$dy * $lwid);
+ $ldy = round($dx * $lwid);
+
+ for ($i = 0; $i < $n; ++$i) {
+ $x = $x0 + $i * $dx + $amp * $dy * sin($k * $i * $step + $phi);
+ $y = $y0 + $i * $dy - $amp * $dx * sin($k * $i * $step + $phi);
+ imagefilledrectangle($this->im, $x, $y, $x + $lwid, $y + $lwid, $this->gdlinecolor);
+ }
+ }
+ }
+
+ /**
+ * Draw the CAPTCHA code over the image
+ *
+ * @access private
+ *
+ */
+ function drawWord()
+ {
+ $width2 = $this->image_width * $this->iscale;
+ $height2 = $this->image_height * $this->iscale;
+
+ if ($this->use_gd_font == true || !is_readable($this->ttf_file)) {
+ if (!is_int($this->gd_font_file)) { //is a file name
+ $font = @imageloadfont($this->gd_font_file);
+ if ($font == false) {
+ trigger_error("Failed to load GD Font file {$this->gd_font_file} ", E_USER_WARNING);
+ return;
+ }
+ } else { //gd font identifier
+ $font = $this->gd_font_file;
+ }
+
+ imagestring($this->im, $font, $this->text_x_start, ($this->image_height / 2) - ($this->gd_font_size / 2), $this->code, $this->gdtextcolor);
+ } else { //ttf font
+ $font_size = $height2 * .35;
+ $bb = imagettfbbox($font_size, 0, $this->ttf_file, $this->code);
+ $tx = $bb[4] - $bb[0];
+ $ty = $bb[5] - $bb[1];
+ $x = floor($width2 / 2 - $tx / 2 - $bb[0]);
+ $y = round($height2 / 2 - $ty / 2 - $bb[1]);
+
+ $strlen = strlen($this->code);
+ if (!is_array($this->multi_text_color)) $this->use_multi_text = false;
+
+
+ if ($this->use_multi_text == false && $this->text_angle_minimum == 0 && $this->text_angle_maximum == 0) { // no angled or multi-color characters
+ imagettftext($this->tmpimg, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code);
+ } else {
+ for($i = 0; $i < $strlen; ++$i) {
+ $angle = rand($this->text_angle_minimum, $this->text_angle_maximum);
+ $y = rand($y - 5, $y + 5);
+ if ($this->use_multi_text == true) {
+ $font_color = $this->gdmulticolor[rand(0, sizeof($this->gdmulticolor) - 1)];
+ } else {
+ $font_color = $this->gdtextcolor;
+ }
+
+ $ch = $this->code{$i};
+
+ imagettftext($this->tmpimg, $font_size, $angle, $x, $y, $font_color, $this->ttf_file, $ch);
+
+ // estimate character widths to increment $x without creating spaces that are too large or too small
+ // these are best estimates to align text but may vary between fonts
+ // for optimal character widths, do not use multiple text colors or character angles and the complete string will be written by imagettftext
+ if (strpos('abcdeghknopqsuvxyz', $ch) !== false) {
+ $min_x = $font_size - ($this->iscale * 6);
+ $max_x = $font_size - ($this->iscale * 6);
+ } else if (strpos('ilI1', $ch) !== false) {
+ $min_x = $font_size / 5;
+ $max_x = $font_size / 3;
+ } else if (strpos('fjrt', $ch) !== false) {
+ $min_x = $font_size - ($this->iscale * 12);
+ $max_x = $font_size - ($this->iscale * 12);
+ } else if ($ch == 'wm') {
+ $min_x = $font_size;
+ $max_x = $font_size + ($this->iscale * 3);
+ } else { // numbers, capitals or unicode
+ $min_x = $font_size + ($this->iscale * 2);
+ $max_x = $font_size + ($this->iscale * 5);
+ }
+
+ $x += rand($min_x, $max_x);
+ } //for loop
+ } // angled or multi-color
+ } //else ttf font
+ //$this->im = $this->tmpimg;
+ //$this->output();
+ } //function
+
+ /**
+ * Warp text from temporary image onto final image.<br />
+ * Modified for securimage
+ *
+ * @access private
+ * @since 2.0
+ * @author Han-Kwang Nienhuys modified
+ * @copyright Han-Kwang Neinhuys
+ *
+ */
+ function distortedCopy()
+ {
+ $numpoles = 3; // distortion factor
+
+ // make array of poles AKA attractor points
+ for ($i = 0; $i < $numpoles; ++$i) {
+ $px[$i] = rand($this->image_width * 0.3, $this->image_width * 0.7);
+ $py[$i] = rand($this->image_height * 0.3, $this->image_height * 0.7);
+ $rad[$i] = rand($this->image_width * 0.4, $this->image_width * 0.7);
+ $tmp = -$this->frand() * 0.15 - 0.15;
+ $amp[$i] = $this->perturbation * $tmp;
+ }
+
+ $bgCol = imagecolorat($this->tmpimg, 0, 0);
+ $width2 = $this->iscale * $this->image_width;
+ $height2 = $this->iscale * $this->image_height;
+
+ imagepalettecopy($this->im, $this->tmpimg); // copy palette to final image so text colors come across
+
+ // loop over $img pixels, take pixels from $tmpimg with distortion field
+ for ($ix = 0; $ix < $this->image_width; ++$ix) {
+ for ($iy = 0; $iy < $this->image_height; ++$iy) {
+ $x = $ix;
+ $y = $iy;
+
+ for ($i = 0; $i < $numpoles; ++$i) {
+ $dx = $ix - $px[$i];
+ $dy = $iy - $py[$i];
+ if ($dx == 0 && $dy == 0) continue;
+
+ $r = sqrt($dx * $dx + $dy * $dy);
+ if ($r > $rad[$i]) continue;
+
+ $rscale = $amp[$i] * sin(3.14 * $r / $rad[$i]);
+ $x += $dx * $rscale;
+ $y += $dy * $rscale;
+ }
+
+ $c = $bgCol;
+ $x *= $this->iscale;
+ $y *= $this->iscale;
+
+ if ($x >= 0 && $x < $width2 && $y >= 0 && $y < $height2) {
+ $c = imagecolorat($this->tmpimg, $x, $y);
+ }
+
+ if ($c != $bgCol) { // only copy pixels of letters to preserve any background image
+ imagesetpixel($this->im, $ix, $iy, $c);
+ }
+ }
+ }
+ }
+
+ /**
+ * Create a code and save to the session
+ *
+ * @access private
+ * @since 1.0.1
+ *
+ */
+ function createCode()
+ {
+ $this->code = false;
+
+ if ($this->use_wordlist && is_readable($this->wordlist_file)) {
+ $this->code = $this->readCodeFromFile();
+ }
+
+ if ($this->code == false) {
+ $this->code = $this->generateCode($this->code_length);
+ }
+
+ $this->saveData();
+ }
+
+ /**
+ * Generate a code
+ *
+ * @access private
+ * @param int $len The code length
+ * @return string
+ */
+ function generateCode($len)
+ {
+ $code = '';
+
+ for($i = 1, $cslen = strlen($this->charset); $i <= $len; ++$i) {
+ $code .= $this->charset{rand(0, $cslen - 1)};
+ }
+ return $code;
+ }
+
+ /**
+ * Reads a word list file to get a code
+ *
+ * @access private
+ * @since 1.0.2
+ * @return mixed false on failure, a word on success
+ */
+ function readCodeFromFile()
+ {
+ $fp = @fopen($this->wordlist_file, 'rb');
+ if (!$fp) return false;
+
+ $fsize = filesize($this->wordlist_file);
+ if ($fsize < 32) return false; // too small of a list to be effective
+
+ if ($fsize < 128) {
+ $max = $fsize; // still pretty small but changes the range of seeking
+ } else {
+ $max = 128;
+ }
+
+ fseek($fp, rand(0, $fsize - $max), SEEK_SET);
+ $data = fread($fp, 128); // read a random 128 bytes from file
+ fclose($fp);
+ $data = preg_replace("/\r?\n/", "\n", $data);
+
+ $start = strpos($data, "\n", rand(0, 100)) + 1; // random start position
+ $end = strpos($data, "\n", $start); // find end of word
+
+ return strtolower(substr($data, $start, $end - $start)); // return substring in 128 bytes
+ }
+
+ /**
+ * Output image to the browser
+ *
+ * @access private
+ *
+ */
+ function output()
+ {
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
+ header("Cache-Control: no-store, no-cache, must-revalidate");
+ header("Cache-Control: post-check=0, pre-check=0", false);
+ header("Pragma: no-cache");
+
+ switch($this->image_type)
+ {
+ case SI_IMAGE_JPEG:
+ header("Content-Type: image/jpeg");
+ imagejpeg($this->im, null, 90);
+ break;
+
+ case SI_IMAGE_GIF:
+ header("Content-Type: image/gif");
+ imagegif($this->im);
+ break;
+
+ default:
+ header("Content-Type: image/png");
+ imagepng($this->im);
+ break;
+ }
+
+ imagedestroy($this->im);
+ exit;
+ }
+
+ /**
+ * Get WAV or MP3 file data of the spoken code.<br />
+ * This is appropriate for output to the browser as audio/x-wav or audio/mpeg
+ *
+ * @since 1.0.1
+ * @return string WAV or MP3 data
+ *
+ */
+ function getAudibleCode($format = 'wav')
+ {
+ $letters = array();
+ $code = $this->getCode();
+
+ if ($code == '') {
+ $this->createCode();
+ $code = $this->getCode();
+ }
+
+ for($i = 0; $i < strlen($code); ++$i) {
+ $letters[] = $code{$i};
+ }
+
+ if ($format == 'mp3') {
+ return $this->generateMP3($letters);
+ } else {
+ return $this->generateWAV($letters);
+ }
+ }
+
+ /**
+ * Set the path to the audio directory.<br />
+ *
+ * @since 1.0.4
+ * @return bool true if the directory exists and is readble, false if not
+ */
+ function setAudioPath($audio_directory)
+ {
+ if (is_dir($audio_directory) && is_readable($audio_directory)) {
+ $this->audio_path = $audio_directory;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Save the code in the session
+ *
+ * @access private
+ *
+ */
+ function saveData()
+ {
+ $_SESSION['securimage_code_value'] = strtolower($this->code);
+ $_SESSION['securimage_code_ctime'] = time();
+
+ $this->saveCodeToDatabase();
+ }
+
+ /**
+ * Validate the code to the user code
+ *
+ * @access private
+ *
+ */
+ function validate()
+ {
+ // retrieve code from session, if no code exists check sqlite database if supported.
+
+ if (isset($_SESSION['securimage_code_value']) && trim($_SESSION['securimage_code_value']) != '') {
+ if ($this->isCodeExpired($_SESSION['securimage_code_ctime']) == false) {
+ $code = $_SESSION['securimage_code_value'];
+ }
+ } else if ($this->use_sqlite_db == true && function_exists('sqlite_open')) { // no code in session - may mean user has cookies turned off
+ $this->openDatabase();
+ $code = $this->getCodeFromDatabase();
+ } else {
+ // session code invalid or non-existant and code not found in sqlite db or sqlite is not available
+ $code = '';
+ }
+
+ $code = trim(strtolower($code));
+ $code_entered = trim(strtolower($this->code_entered));
+ $this->correct_code = false;
+
+ if ($code != '') {
+ if ($code == $code_entered) {
+ $this->correct_code = true;
+ $_SESSION['securimage_code_value'] = '';
+ $_SESSION['securimage_code_ctime'] = '';
+ $this->clearCodeFromDatabase();
+ }
+ }
+ }
+
+ /**
+ * Get the captcha code
+ *
+ * @since 1.0.1
+ * @return string
+ */
+ function getCode()
+ {
+ if (isset($_SESSION['securimage_code_value']) && !empty($_SESSION['securimage_code_value'])) {
+ return strtolower($_SESSION['securimage_code_value']);
+ } else {
+ if ($this->sqlite_handle == false) $this->openDatabase();
+
+ return $this->getCodeFromDatabase(); // attempt to get from database, returns empty string if sqlite is not available or disabled
+ }
+ }
+
+ /**
+ * Check if the user entered code was correct
+ *
+ * @access private
+ * @return boolean
+ */
+ function checkCode()
+ {
+ return $this->correct_code;
+ }
+
+ /**
+ * Generate a wav file by concatenating individual files
+ *
+ * @since 1.0.1
+ * @access private
+ * @param array $letters Array of letters to build a file from
+ * @return string WAV file data
+ */
+ function generateWAV($letters)
+ {
+ $data_len = 0;
+ $files = array();
+ $out_data = '';
+
+ foreach ($letters as $letter) {
+ $filename = $this->audio_path . strtoupper($letter) . '.wav';
+
+ $fp = fopen($filename, 'rb');
+
+ $file = array();
+
+ $data = fread($fp, filesize($filename)); // read file in
+
+ $header = substr($data, 0, 36);
+ $body = substr($data, 44);
+
+
+ $data = unpack('NChunkID/VChunkSize/NFormat/NSubChunk1ID/VSubChunk1Size/vAudioFormat/vNumChannels/VSampleRate/VByteRate/vBlockAlign/vBitsPerSample', $header);
+
+ $file['sub_chunk1_id'] = $data['SubChunk1ID'];
+ $file['bits_per_sample'] = $data['BitsPerSample'];
+ $file['channels'] = $data['NumChannels'];
+ $file['format'] = $data['AudioFormat'];
+ $file['sample_rate'] = $data['SampleRate'];
+ $file['size'] = $data['ChunkSize'] + 8;
+ $file['data'] = $body;
+
+ if ( ($p = strpos($file['data'], 'LIST')) !== false) {
+ // If the LIST data is not at the end of the file, this will probably break your sound file
+ $info = substr($file['data'], $p + 4, 8);
+ $data = unpack('Vlength/Vjunk', $info);
+ $file['data'] = substr($file['data'], 0, $p);
+ $file['size'] = $file['size'] - (strlen($file['data']) - $p);
+ }
+
+ $files[] = $file;
+ $data = null;
+ $header = null;
+ $body = null;
+
+ $data_len += strlen($file['data']);
+
+ fclose($fp);
+ }
+
+ $out_data = '';
+ for($i = 0; $i < sizeof($files); ++$i) {
+ if ($i == 0) { // output header
+ $out_data .= pack('C4VC8', ord('R'), ord('I'), ord('F'), ord('F'), $data_len + 36, ord('W'), ord('A'), ord('V'), ord('E'), ord('f'), ord('m'), ord('t'), ord(' '));
+
+ $out_data .= pack('VvvVVvv',
+ 16,
+ $files[$i]['format'],
+ $files[$i]['channels'],
+ $files[$i]['sample_rate'],
+ $files[$i]['sample_rate'] * (($files[$i]['bits_per_sample'] * $files[$i]['channels']) / 8),
+ ($files[$i]['bits_per_sample'] * $files[$i]['channels']) / 8,
+ $files[$i]['bits_per_sample'] );
+
+ $out_data .= pack('C4', ord('d'), ord('a'), ord('t'), ord('a'));
+
+ $out_data .= pack('V', $data_len);
+ }
+
+ $out_data .= $files[$i]['data'];
+ }
+
+ $this->scrambleAudioData($out_data, 'wav');
+ return $out_data;
+ }
+
+ /**
+ * Randomly modify the audio data to scramble sound and prevent binary recognition.<br />
+ * Take care not to "break" the audio file by leaving the header data intact.
+ *
+ * @since 2.0
+ * @access private
+ * @param $data Sound data in mp3 of wav format
+ */
+ function scrambleAudioData(&$data, $format)
+ {
+ if ($format == 'wav') {
+ $start = strpos($data, 'data') + 4; // look for "data" indicator
+ if ($start === false) $start = 44; // if not found assume 44 byte header
+ } else { // mp3
+ $start = 4; // 4 byte (32 bit) frame header
+ }
+
+ $start += rand(1, 64); // randomize starting offset
+ $datalen = strlen($data) - $start - 256; // leave last 256 bytes unchanged
+
+ for ($i = $start; $i < $datalen; $i += 64) {
+ $ch = ord($data{$i});
+ if ($ch < 9 || $ch > 119) continue;
+
+ $data{$i} = chr($ch + rand(-8, 8));
+ }
+ }
+
+ /**
+ * Generate an mp3 file by concatenating individual files
+ * @since 1.0.4
+ * @access private
+ * @param array $letters Array of letters to build a file from
+ * @return string MP3 file data
+ */
+ function generateMP3($letters)
+ {
+ $data_len = 0;
+ $files = array();
+ $out_data = '';
+
+ foreach ($letters as $letter) {
+ $filename = $this->audio_path . strtoupper($letter) . '.mp3';
+
+ $fp = fopen($filename, 'rb');
+ $data = fread($fp, filesize($filename)); // read file in
+
+ $this->scrambleAudioData($data, 'mp3');
+ $out_data .= $data;
+
+ fclose($fp);
+ }
+
+
+ return $out_data;
+ }
+
+ /**
+ * Generate random number less than 1
+ * @since 2.0
+ * @access private
+ * @return float
+ */
+ function frand()
+ {
+ return 0.0001*rand(0,9999);
+ }
+
+ /**
+ * Print signature text on image
+ *
+ * @since 2.0
+ * @access private
+ *
+ */
+ function addSignature()
+ {
+ if ($this->use_gd_font) {
+ imagestring($this->im, 5, $this->image_width - (strlen($this->image_signature) * 10), $this->image_height - 20, $this->image_signature, $this->gdsignaturecolor);
+ } else {
+
+ $bbox = imagettfbbox(10, 0, $this->signature_font, $this->image_signature);
+ $textlen = $bbox[2] - $bbox[0];
+ $x = $this->image_width - $textlen - 5;
+ $y = $this->image_height - 3;
+
+ imagettftext($this->im, 10, 0, $x, $y, $this->gdsignaturecolor, $this->signature_font, $this->image_signature);
+ }
+ }
+
+ /**
+ * Get hashed IP address of remote user
+ *
+ * @access private
+ * @since 2.0.1
+ * @return string
+ */
+ function getIPHash()
+ {
+ return strtolower(md5($_SERVER['REMOTE_ADDR']));
+ }
+
+ /**
+ * Open SQLite database
+ *
+ * @access private
+ * @since 2.0.1
+ * @return bool true if database was opened successfully
+ */
+ function openDatabase()
+ {
+ $this->sqlite_handle = false;
+
+ if ($this->use_sqlite_db && function_exists('sqlite_open')) {
+ $this->sqlite_handle = sqlite_open($this->sqlite_database, 0666, $error);
+
+ if ($this->sqlite_handle !== false) {
+ $res = sqlite_query($this->sqlite_handle, "PRAGMA table_info(codes)");
+ if (sqlite_num_rows($res) == 0) {
+ sqlite_query($this->sqlite_handle, "CREATE TABLE codes (iphash VARCHAR(32) PRIMARY KEY, code VARCHAR(32) NOT NULL, created INTEGER)");
+ }
+ }
+
+ return $this->sqlite_handle != false;
+ }
+
+ return $this->sqlite_handle;
+ }
+
+ /**
+ * Save captcha code to sqlite database
+ *
+ * @access private
+ * @since 2.0.1
+ * @return bool true if code was saved, false if not
+ */
+ function saveCodeToDatabase()
+ {
+ $success = false;
+
+ $this->openDatabase();
+
+ if ($this->use_sqlite_db && $this->sqlite_handle !== false) {
+ $ip = $this->getIPHash();
+ $time = time();
+ $code = $_SESSION['securimage_code_value']; // hash code for security - if cookies are disabled the session still exists at this point
+ $success = sqlite_query($this->sqlite_handle, "INSERT OR REPLACE INTO codes(iphash, code, created) VALUES('$ip', '$code', $time)");
+ }
+
+ return $success !== false;
+ }
+
+ /**
+ * Get stored captcha code from sqlite database based on ip address hash
+ *
+ * @access private
+ * @since 2.0.1
+ * @return string captcha code
+ */
+ function getCodeFromDatabase()
+ {
+ $code = '';
+
+ if ($this->use_sqlite_db && $this->sqlite_handle !== false) {
+ $ip = $this->getIPHash();
+
+ $res = sqlite_query($this->sqlite_handle, "SELECT * FROM codes WHERE iphash = '$ip'");
+ if ($res && sqlite_num_rows($res) > 0) {
+ $res = sqlite_fetch_array($res);
+
+ if ($this->isCodeExpired($res['created']) == false) {
+ $code = $res['code'];
+ }
+ }
+ }
+
+ return $code;
+ }
+
+ /**
+ * Delete a code from the database by ip address hash
+ *
+ * @access private
+ * @since 2.0.1
+ */
+ function clearCodeFromDatabase()
+ {
+ if ($this->sqlite_handle !== false) {
+ $ip = $this->getIPHash();
+
+ sqlite_query($this->sqlite_handle, "DELETE FROM codes WHERE iphash = '$ip'");
+ }
+ }
+
+ /**
+ * Purge codes over a day old from database
+ *
+ * @access private
+ * @since 2.0.1
+ */