Skip to content

Instantly share code, notes, and snippets.

@shohag-cse-knu
Created December 17, 2024 09:20
Show Gist options
  • Save shohag-cse-knu/cab81e84be0474eb9104b98953f21aec to your computer and use it in GitHub Desktop.
Save shohag-cse-knu/cab81e84be0474eb9104b98953f21aec to your computer and use it in GitHub Desktop.
POST API call using curl in PHP Codeigniter
<?php
$url = base_url().'index.php/controller_name/function_name';
$ch = curl_init($url);
$id = 1;
$code = 'DHA';
$myvars = 'id='.$id.'&code='.$code;
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment