<?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_init('http://192.168.xx.xx:xxxx/ws/live2.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);
// Submit the POST request
$result = curl_exec($ch);
$encode = json_encode($result);
//echo $encode;
$decode = json_decode($encode, true);
print '[' . $decode .']';
//parsing
curl_close($ch);
}
}
?>
<script>
$.ajax({
url : "http://localhost/pduii/index.php/token",
type : "GET",
dataType : "json",
data : {get_param : 'value'},
success : function(data){
var data = data;
alert(data[0]["data"]["token"])
}
});
</script>
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_init('http://192.168.xx.xx:xxxx/ws/live2.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);
// Submit the POST request
$result = curl_exec($ch);
$encode = json_encode($result);
//echo $encode;
$decode = json_decode($encode, true);
print '[' . $decode .']';
//parsing
curl_close($ch);
}
}
?>
<script>
$.ajax({
url : "http://localhost/pduii/index.php/token",
type : "GET",
dataType : "json",
data : {get_param : 'value'},
success : function(data){
var data = data;
alert(data[0]["data"]["token"])
}
});
</script>
Comments
Post a Comment