Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Codeigniter 4 cURL Put Request Example Tutorial

Codeigniter 4 cURL PUT Request Example Tutorial

Posted on September 13, 2021December 13, 2022 By XpertPhp

In this article, we will explain to you how to send php CURL PUT request in Codeigniter 4(Codeigniter 4 cURL PUT Request Example Tutorial). so we will give you a simple example of codeigniter 4 curl example.

normally this request curl method same as the POST request method but when we need to change or update third party API data that time we use cURL PUT Request.

If you want to convert curl to PHP code then you can go to the URL. this converter easily converts the curl code to PHP code.

The php provides four curl request functions like GET, POST, PUT, DELETE. which is used to connect the frontend to the backend as a third party API or resting API. in this example, we are using PHP cURL PUT request in Codeigniter 4. so you can see our following example.

PHP Codeigniter cURL PUT Request example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CurlController extends CI_Controller {
    public function __construct() {
       parent::__construct();
    }
    
    public function curlPutRequest()
    {
/* Endpoint */
$url = 'http://www.localhost.com/endpoint';
 
/* eCurl */
$curl = curl_init($url);
 
/* Set PUT Request */
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
 
/* Data */
$data = [
'name'=>'John Doe',
'email'=>'johndoe@gmail.com'
];
 
/* Set JSON data to PUT*/
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
/* Define content type */
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json'
));
/* Return json */
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
/* make request */
$result = curl_exec($curl);
  
/* close curl */
curl_close($curl);
    }
}
?>
See also  how to get last inserted id in codeigniter example

PHP Codeigniter cURL PUT Request with header authentication example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CurlController extends CI_Controller {
    public function __construct() {
       parent::__construct();
    }
    
    public function curlPutRequest()
    {
/* Endpoint */
$url = 'http://www.localhost.com/endpoint';
 
/* eCurl */
$curl = curl_init($url);
 
/* Set PUT Request */
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
 
/* Data */
$data = [
'name'=>'John Doe',
'email'=>'johndoe@gmail.com'
];
 
/* Set JSON data to PUT*/
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
/* Define content type */
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
'App-Key: JJEK8L4',
'App-Secret: 2zqAzq6'
));
/* Return json */
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
/* make request */
$result = curl_exec($curl);
  
/* close curl */
curl_close($curl);
    }
}
?>

Codeigniter Tags:Codeigniter 4 Tutorial

Post navigation

Previous Post: Codeigniter 4 cURL POST Request Example Tutorial
Next Post: Codeigniter 4 cURL Delete Request Example Tutorial

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com