Topic: Codeigniter

Codeigniter Form Validation with Google reCAPTCHA 0

Codeigniter Form Validation with Google reCAPTCHA

Codeigniter Form Validation with Google reCAPTCHA

In this Post We Will Explain About is Codeigniter Form Validation with Google reCAPTCHA With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Integrate reCAPTCHA in Codeigniter Tutorial Example

In this post we will show you Best way to implement recaptcha example with codeigniter validation, hear for Integrating Google’s reCaptcha in CodeIgniter’s form validation with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

1 Phase # Get an api key for Web-site from google

integrate_codeigniter_recaptcha_with_codeigniter_validation, We must have google gmail account ,go to this simple link and fill the full form like image. google recaptcha with codeigniter

https://www.google.com/recaptcha/admin

2 Phase # copy generated api key/h3>

And then we put codeigniter recaptcha input into simple your HTML form and then put your google api source code into it,After that put api link above the same php file.

<div class="g-recaptcha"></div>

3 Phase # Put CI controller put this simple validation methods

function captcha_validation_google() {
    $google_captcha = $this->input->post('g-recaptcha-response');
    $response_google = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=Google_Your_secreate_key_here &response=" . $google_captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
    if ($response_google . 'success' == false) {
        return FALSE;
    } else {
        return TRUE;
    }
}

after thet you can simple use curl if all the data content php function Like as a file_get_contents not supported by your any linux or more hosting provider simple like this example

function captcha_validation_google() {
    $recaptcha_google = trim($this->input->post('g-recaptcha-response'));
    $userIp_google= $this->input->ip_address();
    // put your google secret key hear
    $google_secret='put-your-secret-key-hear';
    $data_google_captcha = array(
        'secret' => "$google_secret",
        'response' => "$recaptcha_google",
        'remoteip' =>"$userIp_google"
    );
 
    $live_captcha_verfy = curl_init();
    curl_setopt($live_captcha_verfy, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
    curl_setopt($live_captcha_verfy, CURLOPT_POST, true);
    curl_setopt($live_captcha_verfy, CURLOPT_POSTFIELDS, http_build_query($data_google_captcha));
    curl_setopt($live_captcha_verfy, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($live_captcha_verfy, CURLOPT_RETURNTRANSFER, true);
    $captcha_response = curl_exec($live_captcha_verfy);
    $status_capcha= json_decode($captcha_response, true);
    if(empty($status_capcha['success'])){
        return FALSE;
    }else{
        return TRUE;
    }
}

And Then create this simple ci validation rule as well as validation message

$this->form_validation->set_rules('g-recaptcha-response', 'recaptcha validation', 'required|callback_validate_captcha');
$this->form_validation->set_message('captcha_validation_google', 'Again Please check your Google the the captcha form');

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is CodeIgniter 3.0 Form Validation BotDetect CAPTCHA Example And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Return JSON Response in CodeIgniter controller 0

Return JSON Response in CodeIgniter controller

Today, We want to share with you Return JSON Response in CodeIgniter controller.In this post we will show you send json response codeigniter example, hear for codeigniter json encode array we will give you demo and example for implement.In this post, we will learn about codeigniter json response with an example.

Return JSON Response in CodeIgniter controller

There are the Following The simple About Return JSON Response in CodeIgniter controller Full Information With Example and source code.

As I will cover this Post with live Working example to develop get json response php codeigniter, so the codeigniter return json header for this example is following below.

Json Response

public function returnMyProductJson() { 
  header('Content-Type: application/json');
  $productArray = ['id'=>9898, 'name'=>'Mobile'];
  echo json_encode($success);
} 

Completed Source Code

load->helper('url');

  // load view
  $this->load->view('product_view');
 }

 public function productDetails(){
  // POST data
  $postProductData = $this->input->post();

  //load model
  $this->load->model('Main_model');

  // get data
  $data = $this->Main_model->getProductDetails($postProductData);

  echo json_encode($data);
 }

}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to send json response from controller in codeigniter ?.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Codeigniter Retrieve Parameter values passed from View to Controller 0

Codeigniter Retrieve Parameter values passed from View to Controller

Codeigniter Retrieve Parameter values passed from View to Controller

In this Post We Will Explain About is Codeigniter Retrieve Parameter values passed from View to Controller With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Codeigniter – How to get url variable value inside contoller function Example

In this post we will show you Best way to implement GET parameters in the URL with CodeIgniter, hear for Codeigniter passing parameters to controller indexwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

How to get id from URL in codeigniter

VIEW

<h2>How to get current url with query string in codeigniter</h2>
<?php
echo "<a href='product_delete_controller?cat_id=$cat_id'>";
echo $name;
echo "</a>";
?>

if we have to pass the value we should enter simple url like this

https://pakainfo.com/salon/index.php/products_controller/product_delete_controller/70

Controller

in controller function we can read like this

function product_delete_controller( $cat_id = NULL ) {
  echo $cat_id;
}

Onther Way

echo $this->uri->segment('3');

codeigniter get value from url Example

Your URL using Codeigniter View

recieve the param value in a controller from the simple following URL using codeigniter

https://pakainfo.com/salon/c_service/get_Products/items=123

controller

In Codeigniter we can simply do

public function get_Products($items)
{
   var_dump($items); //will output "items=123"
}

How To Get Last ID From URL In Codeigniter

It permits simple we to retrieve a last ID or segment from the URI using Codeigniter Example. There are the following 3 Example to Retrive Codeigniter Last segment.

Example 1 : codeigniter get url query string

$get_last = end($this->uri->segments); 
//Where here best way to, segments is a class simple variable.

Example 2 : php – How to get ID from site url in view page

$get_last = end($this->uri->segment_array());

Example 3 : how to get id from view to controller in codeigniter

$total_seg = $this->uri->total_segments();
$get_last = $this->uri->segment($total_seg);

Example

I hope you have Got What is how to pass id from view to controller in codeigniter And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Codeigniter Create custom library 0

Codeigniter Create custom library

Today, We want to share with you Codeigniter Create custom library.In this post we will show you how to use any library in codeigniter, hear for codeigniter load library in controller we will give you demo and example for implement.In this post, we will learn about How to create custom library file in codeigniter 3 with an example.

Codeigniter Create custom library

There are the Following The simple About Codeigniter Create custom library Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to create plugin in codeigniter, so the create custom library codeigniter Directory structures for this example is following below.

Create a CodeIgniter Libraries

Step 1:-Create Custom Library

first of all you Go to application/libraries as well as here create a new file Yourfilename_lib.php like as a Convertlibrary.php.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source CodeIgniter application development framework for PHP 7.1 or newer
 *
 * @package     CodeIgniter
 * @author      pakainfo
 * @copyright           Copyright (c) 2021, pakainfo.
 * @license     
 * @link        https://pakainfo.com
 * @since       Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * pakainfo core CodeIgniter class
 *
 * @package     CodeIgniter
 * @subpackage          Libraries
 * @category            pakainfo
 * @author      pakainfo
 * @link        https://pakainfo.com
 */

CodeIgniter load pre-defined libraries

class Convertlibrary{
    private $CI;
    public function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');       
        $this->CI->load->database();
        
    }

   function show()
    {
        // Your main logic
    }
}

CodeIgniter load the library

    $this->load->library('convertlibrary');

Step 3: your library method in controller (In any controller)

$this->convertlibrary->show();

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Codeigniter Create custom library.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.