Skip to main content

Posts

Showing posts from May, 2019

CURL di CODEIGNITER

<?php class curl extends CI_Controller { public function __construct() { // created the construct so that the helpers, libraries, models can be loaded all through this controller parent::__construct(); $this->load->helper('url'); $this->load->library('xmlrpc'); $this->load->library('xmlrpcs'); } public function index() { //curl $mytoken = array('act'=>'GetToken', 'username'=>' ***** ', 'password'=>' ******* '); $payload = json_encode($mytoken); $ch = curl_init('http://192.168.30.99:8082/ws/live2.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json',

Json encode dan decode

Logic Behind json encode and decode Encode array to json using  json_encode() <?php // This is a simple array $var1 = array( 'key_name1' => 'value_name1', 'key_name2' => 'value_name2' ); //We are converting array in encode $var1 array to json using json encode $encode_data = json_encode($var1); echo $encode_data; ?> Copy Result: Array Converted to JSON {"key_name":"value_name","key_name1":"value_name1"} Copy Decode json to array using  json_decode() <?php // This is a simple array, We are converting array in $var1 = array( 'key_name1' => 'value_name1', 'key_name2' => 'value_name2' ); //encode $var1 array to json using json_encode() $encode_data = json_encode($var1); echo $encode_data; //decode json data($encode_data) to array, using json_decode() $decode_data = json_decode($encode_data); print_r($decode_data); ?> Copy Result:

Token_Model

<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Token_model extends CI_Model { public function __construct() { parent::__construct(); $this->load->library('session'); $this->load->helper('url'); } public function token_feeder() { $username = '*****'; $password = '*****'; $data_sesi=array( 'username'=>$username, 'password'=>$password, 'sudah_login'=>true, ); $this->session->set_userdata($data_sesi); $username=$this->session->userdata('username'); $password=$this->session->userdata('password'); $mytoken = array('act'=>'GetToken', 'username'=>$username, 'password'=>$password); $payload = json_encode($mytoken); $ch = curl_init('http://192.168.30.99:8082/ws/live2.php'); curl_setopt($ch, CURLOPT_RETURNTRANS

ws_client_act

<?php defined('BASEPATH') OR exit('No direct script access allowed'); error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE ^ E_DEPRECATED); session_start(); class Ws_Client extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); $this->load->helper('url'); $this->load->model('token/token_model','tkn'); } public function index() { $token = $this->tkn->token_feeder(); echo $token; } public function client() { $token = $this->tkn->token_feeder(); $filter = ''; $order = ''; $limit = 100; $offset = 0; $myProfil = array('act'=>'GetMatkulKurikulum', 'token'=>$token, 'filter'=>$filter, 'order'=>$order, 'limit'=>$limit, 'offset'=>$offset); $profil_pt = json_encode($myProfil); $ch = curl_init('http://

Latihan

<html>     <head>         <script src="jquery-1.12.0.min.js"></script>         <script> $.ajax({ url         : "json.php", type        : "GET", dataType    : "json", data        : {get_param : 'value'}, success     : function(data){ var data = data; alert(data[0]["data"]["token"]) } }); </script>     </head> <body>     </body> </html>

Token

<?php defined('BASEPATH') OR exit('No direct script access allowed'); error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE ^ E_DEPRECATED); session_start(); class Token extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); } public function index() { $username = 'xxxxxx'; $password = 'xxxxxx'; $data_sesi=array( 'username'=>$username, 'password'=>$password, 'sudah_login'=>true, ); $this->session->set_userdata($data_sesi); //ambil token $username=$this->session->userdata('username'); $password=$this->session->userdata('password'); $mytoken = array('act'=>'GetToken', 'username'=>$username, 'password'=>$password); $payload = json_encode($mytoken);   // Prepare new cURL resource $ch = curl_ini

JSON pada PHP

Sebelum menerapkan bentuk Json pada PHP kita terlebih dahulu memperkenalkan apa itu Json, pengertian Json itu sebenarnya, fungsi Json pada PHP, dan penerapanya pada PHP itu bagai mana. Json ini nanti juga dapat kita temui seperti Web Service yang pernah saya temui pada Sistem Aplikasi FEEDER PDPT Dikti, Setiap Kampus pada saat ini mengikuti FEEDER ini. Sangat penting kita dalam mengenal Json ini. Apa itu Json ? JSON merupakan singkata dari  JavaScript Object Notation  (  notasi objek JavaScript  ). Json ini biasa dilafalkan oleh berberapa orang  JASON.  Json ini merupakan format singkat dari pertukaran data pada sistemnya, yang nantinya akan ditampilkan seperti format Text yang ditampilkan pada user. Format JSON biasanya untu melakukan  transmisi data struktur melalui Token tertentu untuk mendapatkan proses yang biasanya disebut  serialisasi . Contohnya Aplikasi web AJAX yang berperan untuk alternatif terhadap penggunaan format XML. Harus kita ketahui dasarnya, JSON dian