I'm trying to create a registration form with a captcha, using this tutorial, but I don't know how to validate the captcha, can you help me?
Pada bagian ini, saya membahas kode PHP untuk membuat kode CAPTCHA untuk disimpan dalam variabel sesi. Saya memulai session untuk menyimpan captcha yang dibuat secara dinamis menggunakan fungsi rand PHP. Saya telah membuat layer target gambar dan menulis kode acak. Gambar captcha JPEG ini akan ditampilkan dalam form kontak. Action, action pada form di atas bisa di istilahkan sebagai navigator. Jangan lupa untuk menambahkan query ID dan set Auto Increment untuk query ID. Form Input Data Ke Database Dengan PHP-MySQL (Sederhana) – Part 1” Ashari Ramdhan says: March 10, 2019 at 9:27 am.
1 Answer
Captcha is just any string created using image library.Process as below:
1- create random or dictionary word string2- store it anywhere [session in your case before displaying your registration form3- compare session value to user submit value
Your code :
$_SESSION['randomnr2'] is random string created and stored in session.before storing it is md5 encrypted.
Not the answer you're looking for? Browse other questions tagged phpcaptcha or ask your own question.
Seegatesite.com – Make simple CRUD web application using Datatables, Jquery and adminLTE is fast and efficient measures. I will share how utilizing datatables plugin to display data from the server to the browser using AJAX in order to look more interactive table. In addition Datatables plugin, jquery and adminlte use to make the system more attractive and responsive. Let’s start the following tutorial.
Table of Contents
- 1 Tutorial Create Simple CRUD with Datatables, Jquery and AdminLTE
Tutorial Create Simple CRUD with Datatables, Jquery and AdminLTE
Requirement :
- AdminLTE Theme. Download here
- Plugin Datatables (Already contained in adminlte).
- Jquery (Already contained in adminlte).
- Plugin SweetAlert (To beautify the javascript alert, please download here).
- Plugin Bootstrap-Notify (To beautify the notification, please download here).
Other article : Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1
- Create MYSQL database with names “crud”
- Add the customer table in the database crud
- Add the following query as the initial data customer table.2INSERT INTO customer(NAME,gender,country,phone)VALUES('Sigit Prasetya N','Male','Indonesia','000-857489');INSERT INTO customer(NAME,gender,country,phone)VALUES('Taylor Swift','Female','United State','0858774858');INSERT INTO customer(NAME,gender,country,phone)VALUES('Kristen Stewart','Female','British','888-985859');
- Extracts adminlte.zip that you downloaded earlier on your public folder (if using xampp, at the htdocs folder inside / ubuntu in the folder /var/www/html/) and rename the folder adminlte be crud.
- Copy plugin sweetalert (sweetalert.css and sweetalert.min.js) into the folder crud/plugins/sweetalert/
- Copy plugin bootstrap-notify (bootstrap-notify.min.js) into the folder /crud/plugin/bootstrap-notify/
- Create a new folder with the name “application” in the crud folder, and then create a folder inside “application” folder with the name “customer“.
- Get blank.html file (/crud/pages/examples/blank.html), copy to folder /crud/application/customer/ and rename it to index.php
- Edit index.php, then add the css and js files below2468101214<link rel='stylesheet'href='../../plugins/sweetalert/sweetalert.css'><!--responsive datatables--><link rel='stylesheet'href='../../plugins/datatables/extensions/Responsive/css/dataTables.responsive.css'><!--........content.............--><!--SweetAlert--><script src='../../plugins/sweetalert/sweetalert.min.js'></script><script src='../../plugins/bootstrap-notify/bootstrap-notify.min.js'></script><script src='../../plugins/datatables/jquery.dataTables.min.js'></script><script src='../../plugins/datatables/dataTables.bootstrap.min.js'></script><script src='../../plugins/datatables/extensions/Responsive/js/dataTables.responsive.min.js'></script>
- Edit
section
in index.php and paste the following script246810121416182022242628303234363840424446485052545658606264666870727476788082<!--=--><section class='content'><div class='box'><button type='submit'class='btn btn-primary 'id='btnadd'name='btnadd'><iclass='fa fa-plus'></i>Add Customer</button><table id='table_cust'class='table table-striped table-bordered table-hover'><tr class='tableheader'><th style='width:140px'>Name</th><th style='width:140px'>Country</th><th></th></thead></tbody></div></div><div id='modalcust'class='modal'><div class='modal-content'><button type='button'class='close'data-dismiss='modal'>×</button></div><div class='modal-body'><div class='form-horizontal'><label class='col-sm-3 control-label'>Name</label><input type='text'class='form-control'id='txtname'placeholder='Name'><input type='hidden'id='txtid'value='0'></div><label class='col-sm-3 control-label'>Gender</label><select class='form-control'id='cbogender'><option value='Female'>Female</option></div><div class='form-group'><label class='col-sm-3 control-label'>Country</label><input type='text'class='form-control'id='txtcountry'></div><label class='col-sm-3 control-label'>Phone</label><input type='text'class='form-control'id='txtphone'></div><label class='col-sm-3 control-label'></label><button type='submit'class='btn btn-primary 'id='btnsave'><iclass='fa fa-save'></i>Save</button></div></div></div></div></div></div><!--/.content--><!--=--> - Create 4 php file in the customer folderdata.php : This file is used to display customer data using ajax on datatables.copy the following code on data.php24681012141618include'../config.php';$query=mysql_query('SELECT @rownum := @rownum + 1 AS urutan,t.*(SELECT @rownum := 0) r');while($r=mysql_fetch_assoc($query)){}foreach($dataas$key){$data[$i]['button']='<button type='submit' id_cust='.$data[$i]['id_cust'].' ><i></i></button><button type='submit' id_cust='.$data[$i]['id_cust'].' name_cust='.$data[$i]['name'].' ><i></i></button>';}echojson_encode($datax);
get_cust.php : This file is used to retrieve customer data with a specific id when btnedit button on click. copy the following code in the file get_cust.php<?phpinclude'../config.php';$id_cust=$_POST['id_cust'];$query=mysql_query('select * from customer where id_cust=$id_cust');$array=array();while($data=mysql_fetch_array($query)){$array['id_cust']=$data['id_cust'];$array['name']=$data['name'];$array['gender']=$data['gender'];$array['country']=$data['country'];$array['phone']=$data['phone'];}echojson_encode($array);?>
save.php : This file is used to store and update customer table in the database. copy the following code in the file save.php<?phpinclude'../config.php';$id_cust=$_POST['id_cust'];$name=$_POST['name'];$gender=$_POST['gender'];$country=$_POST['country'];$phone=$_POST['phone'];$crud=$_POST['crud'];if($crud'N'){mysql_query('insert into customer(name,gender,country,phone) values('$name','$gender','$country','$phone')');if(mysql_error()){$result['error']=mysql_error();$result['result']=0;}else{$result['error']=';$result['result']=1;}}elseif($crud'E'){mysql_query('update customer set name='$name',gender='$gender',country='$country',phone='$phone' where id_cust=$id_cust');if(mysql_error()){$result['error']=mysql_error();$result['result']=0;}else{$result['error']=';$result['result']=1;}}else{$result['error']='Invalid Order';$result['result']=0;}$result['crud']=$crud;echojson_encode($result);?>
delete.php : This file is used to delete the customer data in the database.copy the following code on delete.php<?phpinclude'../config.php';$id_cust=$_POST['id_cust'];mysql_query('delete from customer where id_cust=$id_cust');if(mysql_error()){$result['error']=mysql_error();$result['result']=0;}else{$result['error']=';$result['result']=1;}echojson_encode($result);?> - Create a javascript file with the name customer.js and put in the same folder as index.php and copy the following script on customer.js2468101214161820222426283032343638404244464850525456586062646668707274767880828486889092949698100102104106108110112114116118120122124126128130132134136138140142144146148150152154156158160162164166168{'paging':true,'searching':true,'info':false,'autoWidth':false,'ajax':{'type':'POST''columns':[{'data':'name'},{'data':'country'},{'data':'button'},});$(document).on('click','#btnadd',function(){$('#txtname').focus();$('#txtcountry').val(');$('#crudmethod').val('N');});varid_cust=$(this).attr('id_cust');swal({text:'Delete Cust : '+name+' ?',showCancelButton:true,confirmButtonText:'Delete',function(){id_cust:id_cust$.ajax(url:'delete.php',data:value,{if(data.result1){vartable=$('#table_cust').DataTable();}else{swal('Error','Can't delete customer data, error : '+data.error,'error');error:function(jqXHR,textStatus,errorThrown)swal('Error!',textStatus,'error');});});varid_cust=$('#txtid').val();vargender=$('#cbogender').val();varphone=$('#txtphone').val();if(name'||namenull){swal('Warning','Please fill customer name','warning');return;varvalue={name:name,country:country,crud:crud$.ajax(url:'save.php',data:value,{if(data.crud'N'){$.notify('Successfull save data');table.ajax.reload(null,false);$('#txtname').val(');$('#txtphone').val(');$('#txtid').val('0');}else{swal('Error','Can't save customer data, error : '+data.error,'error');}elseif(data.crud'E'){$.notify('Successfull update data');table.ajax.reload(null,false);}else{swal('Error','Can't update customer data, error : '+data.error,'error');}else{}error:function(jqXHR,textStatus,errorThrown)swal('Error!',textStatus,'error');});$(document).on('click','.btnedit',function(){varvalue={};{type:'POST',success:function(data,textStatus,jqXHR)vardata=jQuery.parseJSON(data);$('#txtid').val(data.id_cust);$('#cbogender').val(data.gender);$('#txtphone').val(data.phone);$('#modalcust').modal('show');},{}});type:'success',});
Don’t forget to call the customer.js script by putting script at the end of the line on index.php
A short explanation :
– $('#table_cust').DataTable({ ................}); -
Used to display customer data in the data tables using ajax when document is already.
– $(document).on('click','#btnadd',function(){ .. }) -
When a add customer button is pressed, the jquery will run the script
– $(document).on( 'click','.btnhapus', function() { .. }) -
When the button with “.btnhapus” class clicked, jquery will run the script above to delete customer data
– $(document).on('click','#btnsave',function(){ .. }) -
When the button with id “btnsave” clicked , jquery will run a script to store / update customer data
– To reload or refresh datatables’s data, we need to reload the datatables with script below
2 | table.ajax.reload(null,false); |
13. Don’t forget to create config.php on the application folder
<?php$host='localhost';$user='root';$pwd=';$dbname='crud';$link=mysql_connect($host,$user,$pwd);$db=mysql_select_db($dbname,$link);if(!$db)die('failed to connect to database.......');?> |
Done, simple CRUD with datatables, jquery and adminlte been completed. Please test your project in the browser with the address http://localhost/crud/application/customer. If successful, the display on your browser will be as follows
If you need a complete file please download the link below
Download : Simple CRUD with Datatables, jQuery and AdminLTE Source Code
Password : seegatesite.com
My other article : Showing Mysql Data To Html Tables With Many Options with Jquery And AdminLTE
Update : I create new Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1, Please take your time reading this article to get the latest knowledge