Komentar untuk "Membuat Captcha dengan PHP"

Faizal Haq
November 21, 2012 | 08:11 pm
min punya contoh sistem pakar menggunakan forward chaining g?klo ada blh mnta source code nya..lg btuh bgt nih..thanks
November 21, 2012 | 03:57 pm
Ada namanya OCR - Optical character recognition untuk membaca text dari sebuah gambar.
mokegile
November 20, 2012 | 10:47 pm
kalo decode dari image captcha ke teks gimana ya mas?
Faizal Haq
October 16, 2012 | 08:20 am
thanks mas atas bantuannya. :)
October 15, 2012 | 09:03 pm
  1. <?php
  2. session_start();
  3. require_once('config/config.php');
  4. require_once('config/function.php');
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <title>System Pakar</title>
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  11. <link href="asset/css/style.css" rel="stylesheet" type="text/css" />
  12. <link href="asset/css/pagging.css" rel="stylesheet" type="text/css" />
  13. <link href="asset/UI/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
  14.  
  15. <script type="text/javascript" src="asset/js/jquery-1.7.1.min.js"></script>
  16. <script type="text/javascript" src="asset/js/jquery.validate.js"></script>
  17. <script type="text/javascript" src="asset/js/jquery.ui.core.js"></script>
  18. <script type="text/javascript" src="asset/js/jquery.ui.datepicker.js"></script>
  19. <script type="text/javascript" src="asset/js/jquery.inc.check-form.js"></script>
  20. <script type="text/javascript" src="asset/js/jquery.inc.validasi.js"></script>
  21.  
  22. <script type="text/javascript">
  23. $(document).ready(function(){
  24.  
  25. $( "#tgl" ).datepicker({
  26. dateFormat: "yy-mm-dd",
  27. changeMonth: true,
  28. changeYear: true
  29. });
  30.  
  31. $("#fdaftar").validate({
  32. debug: false,
  33. rules: {
  34. nama: {
  35. required: true
  36. },
  37. alamat: {
  38. required: true
  39. },
  40. tgl: {
  41. required: true
  42. },
  43. tlp: {
  44. required: true,
  45. number: true
  46. },
  47. username: {
  48. required: true
  49. },
  50. pass: {
  51. required: true,
  52. },
  53. ulangi_pass: {
  54. required: true,
  55. equalTo: "#pass"
  56. },
  57. },
  58. messages: {
  59. nama: {
  60. required: "Nama user harus diisi !"
  61. },
  62. alamat: {
  63. required: "Alamat harus diisi !"
  64. },
  65. tgl: {
  66. required: "Tanggal lahir harus diisi !"
  67. },
  68. tlp: {
  69. required: "No telepon harus diisi !",
  70. number: "Harus berupa angka !"
  71. },
  72. username: {
  73. required: "Username harus diisi !"
  74. },
  75. pass: {
  76. required: "Password harus diisi !"
  77. },
  78. ulangi_pass: {
  79. required: "Ulangi Password !",
  80. equalTo: "Password tidak sama !"
  81. }
  82. },
  83. });
  84.  
  85. });
  86. </script>
  87.  
  88. </head>
  89. <body>
  90. <?php
  91. if($_POST){
  92. if(md5($_POST['pin']) == $_SESSION['image_random_value']){
  93. echo '<p>You are people</p>';
  94. }else{
  95. $nama = xss_clean($_POST['nama']);
  96. $alamat = xss_clean($_POST['alamat']);
  97. $tgl = xss_clean($_POST['tgl']);
  98. $tlp = xss_clean($_POST['tlp']);
  99. $username = xss_clean($_POST['username']);
  100. $pass = xss_clean($_POST['pass']);
  101.  
  102. @mysql_query("INSERT INTO tbl_user (username,password,nama,alamat,tgl_lahir,no_tlp) VALUES('$username',MD5('$pass'),'$nama','$alamat','$tgl','$tlp')");
  103.  
  104. echo "<script type='text/javascript'>alert('Data sudah disimpan, silakan untuk login !');</script>";
  105. }
  106. }
  107. ?>
  108.  
  109. <div id="container">
  110. <div class="logo"><img src="asset/images/header.png" height="128" width="742" /></div>
  111. <div class="tabs">
  112. <br /><br />
  113. <br />
  114. <br />
  115.  
  116. <a href="index.php" class="first_tab">Menu Utama</a>
  117. </div>
  118.  
  119. <div id="content">
  120. <form id="fdaftar" name="fdaftar" method="post" action="page_daftarbaru.php">
  121. <table>
  122. <tr>
  123. <td>Nama Lengkap</td>
  124. <td>:</td>
  125. <td><input type="text" id="nama" name="nama" /></td>
  126. </tr>
  127. <tr>
  128. <td>Alamat</td>
  129. <td>:</td>
  130. <td><textarea id="alamat" name="alamat" cols="50" rows="5"></textarea></td>
  131. </tr>
  132. <tr>
  133. <td>Tanggal Lahir</td>
  134. <td>:</td>
  135. <td><input type="text" id="tgl" name="tgl" /></td>
  136. </tr>
  137. <tr>
  138. <td>No Telepon</td>
  139. <td>:</td>
  140. <td><input type="text" id="tlp" name="tlp"/></td>
  141. </tr>
  142. <tr>
  143. <td>Username</td>
  144. <td>:</td>
  145. <td><input type="text" id="username" name="username" /></td>
  146. </tr>
  147. <tr>
  148. <td>Password</td>
  149. <td>:</td>
  150. <td><input type="password" id="pass" name="pass" /></td>
  151. </tr>
  152. <tr>
  153. <td>Ulangi Password</td>
  154. <td>:</td>
  155. <td><input type="password" id="ulangi_pass" name="ulangi_pass" /></td>
  156. </tr>
  157. <tr>
  158. <td></td>
  159. <td></td>
  160. <td>
  161. <img src="captcha.php?date=<?php echo date('YmdHis');?>" alt="security image" />
  162. <div>
  163. Input Text Above: <input type="text" name="pin" />
  164. <input type="submit" name="submit" value="Submit" />
  165. </div>
  166. </td>
  167. </tr>
  168.  
  169. </form>
  170.  
  171. </div>
  172. <div id='footer'>
  173. <div class='left_footer'>System Pakar Penyakit Mata &copy; 2012 by M. Faizal Haq</div>
  174. </div>
  175.  
  176. </div>
  177.  
  178. </body>
  179. </html>
Faizal Haq
October 15, 2012 | 07:29 pm
mas mau tanya, saya udh sisipkan captcha itu ke dalam form pendaftaran yg saya buat tetapi tidak dapat menyimpan. bagaimana cara nya y mas? ini saya sisipkan kodenya mas, mohon pencerahannya. thanks
  1. <?php
  2. require_once('config/config.php');
  3. require_once('config/function.php');
  4. ?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <title>System Pakar</title>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  10. <link href="asset/css/style.css" rel="stylesheet" type="text/css" />
  11. <link href="asset/css/pagging.css" rel="stylesheet" type="text/css" />
  12. <link href="asset/UI/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
  13.  
  14. <script type="text/javascript" src="asset/js/jquery-1.7.1.min.js"></script>
  15. <script type="text/javascript" src="asset/js/jquery.validate.js"></script>
  16. <script type="text/javascript" src="asset/js/jquery.ui.core.js"></script>
  17. <script type="text/javascript" src="asset/js/jquery.ui.datepicker.js"></script>
  18. <script type="text/javascript" src="asset/js/jquery.inc.check-form.js"></script>
  19. <script type="text/javascript" src="asset/js/jquery.inc.validasi.js"></script>
  20.  
  21. <script type="text/javascript">
  22. $(document).ready(function(){
  23.  
  24. $( "#tgl" ).datepicker({
  25. dateFormat: "yy-mm-dd",
  26. changeMonth: true,
  27. changeYear: true
  28. });
  29.  
  30. $("#fdaftar").validate({
  31. debug: false,
  32. rules: {
  33. nama: {
  34. required: true
  35. },
  36. alamat: {
  37. required: true
  38. },
  39. tgl: {
  40. required: true
  41. },
  42. tlp: {
  43. required: true,
  44. number: true
  45. },
  46. username: {
  47. required: true
  48. },
  49. pass: {
  50. required: true,
  51. },
  52. ulangi_pass: {
  53. required: true,
  54. equalTo: "#pass"
  55. },
  56. },
  57. messages: {
  58. nama: {
  59. required: "Nama user harus diisi !"
  60. },
  61. alamat: {
  62. required: "Alamat harus diisi !"
  63. },
  64. tgl: {
  65. required: "Tanggal lahir harus diisi !"
  66. },
  67. tlp: {
  68. required: "No telepon harus diisi !",
  69. number: "Harus berupa angka !"
  70. },
  71. username: {
  72. required: "Username harus diisi !"
  73. },
  74. pass: {
  75. required: "Password harus diisi !"
  76. },
  77. ulangi_pass: {
  78. required: "Ulangi Password !",
  79. equalTo: "Password tidak sama !"
  80. }
  81. },
  82. });
  83.  
  84. });
  85. </script>
  86.  
  87. </head>
  88. <body>
  89.  
  90. <?php
  91. if($_REQUEST['action'] == "proses")
  92. {
  93. $nama = xss_clean($_POST['nama']);
  94. $alamat = xss_clean($_POST['alamat']);
  95. $tgl = xss_clean($_POST['tgl']);
  96. $tlp = xss_clean($_POST['tlp']);
  97. $username = xss_clean($_POST['username']);
  98. $pass = xss_clean($_POST['pass']);
  99.  
  100. @mysql_query("INSERT INTO tbl_user (username,password,nama,alamat,tgl_lahir,no_tlp) VALUES('$username',MD5('$pass'),'$nama','$alamat','$tgl','$tlp')");
  101.  
  102. echo "<script type='text/javascript'>alert('Data sudah disimpan, silakan untuk login !');</script>";
  103. }
  104. ?>
  105. <?php
  106. if($_POST['submit']){
  107. session_start();
  108. if(md5($_POST['pin']) == $_SESSION['image_random_value']){
  109. echo '<p>You are people</p>';
  110. }else{
  111. @mysql_query("INSERT INTO tbl_user (username,password,nama,alamat,tgl_lahir,no_tlp) VALUES('$username',MD5('$pass'),'$nama','$alamat','$tgl','$tlp')");
  112. echo '<p>Are you human being?</pa>';
  113. }
  114. }
  115. ?>
  116.  
  117. <div id="container">
  118. <div class="logo"><img src="asset/images/header.png" height="128" width="742" /></div>
  119. <div class="tabs">
  120. <br /><br />
  121. <br />
  122. <br />
  123.  
  124. <a href="index.php" class="first_tab">Menu Utama</a>
  125. </div>
  126.  
  127. <div id="content">
  128. <form id="fdaftar" name="fdaftar" method="post" action="page_daftarbaru.php">
  129. <table>
  130. <tr>
  131. <td>Nama Lengkap</td>
  132. <td>:</td>
  133. <td><input type="text" id="nama" name="nama" /></td>
  134. </tr>
  135. <tr>
  136. <td>Alamat</td>
  137. <td>:</td>
  138. <td><textarea id="alamat" name="alamat" cols="50" rows="5"></textarea></td>
  139. </tr>
  140. <tr>
  141. <td>Tanggal Lahir</td>
  142. <td>:</td>
  143. <td><input type="text" id="tgl" name="tgl" /></td>
  144. </tr>
  145. <tr>
  146. <td>No Telepon</td>
  147. <td>:</td>
  148. <td><input type="text" id="tlp" name="tlp"/></td>
  149. </tr>
  150. <tr>
  151. <td>Username</td>
  152. <td>:</td>
  153. <td><input type="text" id="username" name="username" /></td>
  154. </tr>
  155. <tr>
  156. <td>Password</td>
  157. <td>:</td>
  158. <td><input type="password" id="pass" name="pass" /></td>
  159. </tr>
  160. <tr>
  161. <td>Ulangi Password</td>
  162. <td>:</td>
  163. <td><input type="password" id="ulangi_pass" name="ulangi_pass" /></td>
  164. </tr>
  165. <form name="form1" method="post" action="">
  166. <img src="captcha.php?date=<?php echo date('YmdHis');?>" alt="security image" />
  167. <div>
  168. Input Text Above: <input type="text" name="pin" />
  169. <input type="submit" name="submit" value="Submit" />
  170. </div>
  171. </form>
  172. <tr>
  173. <td></td>
  174. <td></td>
  175. <td>&nbsp;</td>
  176. </tr>
  177.  
  178. </form>
  179.  
  180. </div>
  181. <div id='footer'>
  182. <div class='left_footer'>System Pakar Penyakit Mata &copy; 2012 by M. Faizal Haq</div>
  183. </div>
  184.  
  185. </div>
  186.  
  187. </body>
  188. </html>
  189.  
baybay
July 12, 2012 | 01:49 pm
@admin : Oke.. terima kasih banyak atas bantuannya mas..
Alhamdulillah lancar.. :D jadi tambah asik belajar bahasa pemrograman nih..
MyPHPtutorials
July 11, 2012 | 11:19 am
sama saja! tinggal tambahkan textbox pada contoh ke dalam form milikmu. trus validasi inputan captcha sebelum data disimpan contoh:
  1. <?php
  2. if($_POST['submit']){
  3. session_start();
  4. if(md5($_POST['pin']) != $_SESSION['image_random_value']){
  5. echo 'Captcha salah!';
  6. }else{
  7. //simpan datanya
  8. }
  9. }
  10. ?>
baybay
July 11, 2012 | 07:55 am
Mas, masih bingung nih kalo diintegerasikan dengan inout text yang lain..
habis di contohnya cuma ada satu input text dan itu pun unuk mengisi captcha,.. :(

Tolong bantuannya mas ellyx.. :(
July 05, 2012 | 08:26 am
@Devil'z Luluna: pertama kenapa kamu perlu menyimpan captcha?
kalau ditutorial ini text yang ditulis di captcha bisa diperoleh dari $_SESSION['image_random_value']