Last active
March 20, 2017 03:49
-
-
Save tri82wiyono/0efd353a7696b0fd2182f421b552fe6a to your computer and use it in GitHub Desktop.
fungsi login ke host to host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
fungsi ini saya buat ada ceritanya, dan aplikasi ini host to host dengan kementrian, nah di spek mereka itu ketika Bank untuk mau | |
Get dan Post data headernya harus berisikan token, jadi token tersebut sebagai otentikasinya. dan awalnya setiap login mereka selalu | |
memberikan token, jadi saya ubah konsepnya gimana supaya aplikasi saya tidak berulang get token. sehingga saya buatlan fungsinya dibawa ini | |
saya tidak jelasan tiap2 baris, | |
jadi kalo ada yang mau ditanyak silahkan hubungi saya : | |
eMail : tri82.wiyono@gmail.com | |
website : www.triwiyono.com | |
*/ | |
var API = ""; | |
$this->API = "http://iphost/"; | |
function authSIKP(){ | |
$username = $this->input->post('username',TRUE); | |
$password = $this->input->post('password',TRUE); | |
$data = array( | |
'username' => $this->input->post('username',TRUE), | |
'password' => $this->input->post('password',TRUE), | |
); | |
$date = date("Y-m-d"); | |
$time = date("H:i:s"); | |
$cekToken = $this->Sess_token_model->cekToken($date); | |
if($cekToken->num_rows()>0){ | |
$dataToken = $cekToken->row_array(); | |
$this->session->set_userdata('token',$dataToken['kode_token']); | |
redirect(site_url('hostname')); | |
} else { | |
$dataJSON = json_encode($data); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $this->API.'/auth'); | |
curl_setopt($ch, CURLOPT_POST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJSON); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$response = json_decode(curl_exec($ch)); //respond | |
$this->session->set_userdata('token',$response->message); | |
curl_close($ch); | |
$dataToken = array( | |
'id' => $this->session->userdata('uid'), | |
'username' => $this->session->userdata('uname'), | |
'date' => $date, | |
'time' => $time, | |
'kode_token' => $this->session->userdata('token') | |
); | |
$this->Sess_token_model->insertToken($dataToken); | |
$this->session->set_flashdata('message','token berhasil disimpan'); | |
redirect(site_url('hostname')); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment