Advertisement
GWibisono

sekalian black box

Feb 16th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. if ( ! function_exists('_runApi')){
  5.     function _runApi($url, $parameter=array()){
  6.     global $maxTime;
  7.     $dtAPI=array('url'=>$url);
  8.     if(count($parameter)){
  9.         $logTxt="func:_runApi| url:{$url}| param:".http_build_query($parameter,'','&');
  10.         //$dtAPI['parameter']=json_encode($parameter);
  11.     }
  12.     else{
  13.         $logTxt="func:_runApi| url:{$url}";
  14.         //$dtAPI['parameter']='-';
  15.         $parameter['info']='no post';      
  16.     }
  17.     $parameter[]=array('server'=>$_SERVER);
  18.     $dtAPI['parameter']=json_encode($parameter);
  19.  
  20.         $curl = curl_init();
  21.          
  22.         curl_setopt($curl, CURLOPT_URL, $url  );
  23.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  24.         if($parameter != '' && count($parameter)!=0 ) {
  25.             curl_setopt($curl, CURLOPT_POST, true);
  26.             curl_setopt($curl, CURLOPT_TIMEOUT, $maxTime);
  27.             curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameter,'','&'));
  28.             if( isset($_SERVER['HTTP_USER_AGENT']) ) curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  29.             logCreate('API:POST','info');
  30.         }else{
  31.             logCreate('API:GET','info');
  32.         }
  33.        
  34.         $response = curl_exec($curl);
  35.  
  36.         if (0 != curl_errno($curl)) {
  37.             $response = new stdclass();
  38.             $response->code = '500';
  39.             $response->message = curl_error($curl);
  40.             $dtAPI['response']=json_encode($response );
  41.             $dtAPI['error']=1;
  42.         }
  43.         else{
  44.             $response0 = $response;
  45.             $dtAPI['response']= $response ;
  46.             $dtAPI['error']=0;
  47.             $response = json_decode($response,1);
  48.             if(!is_array($response)){
  49.                 $response=$response0;
  50.                 $dtAPI['error']=1;
  51.             }
  52.             else{
  53.                 $dtAPI['error']=0;
  54.             }
  55.         }
  56.        
  57.         curl_close($curl);
  58.         if(!isset($response0)) $response0='?';
  59.         logCreate( 'API |url:'. $url. "|raw:".(is_array($response)?'total array/obj='.count($response):$response0 ) );
  60.          
  61.         return $response;
  62.            
  63.     }
  64. } else{}
  65.  
  66. $param=array(
  67.                 'type'=>'updateDetail',
  68.                 'data'=>array(                   
  69.                 ),
  70.                 'recover'=>true
  71.             );
  72.  
  73.             foreach($this->input->post() as $name=>$value){
  74.                 $param['data'][]=array( 'name'=>$name, 'value'=>$value);
  75.             }
  76.  
  77.             $param['data'][]=array( 'name'=>'detail','value'=>$this->param['detail']['detail']);
  78.             $param['data'][]=array( 'name'=>'username','value'=>$this->param['detail']['username']);
  79. //----------UPDATE Agar dapat di LOG           
  80.             $result= _runApi($url,$param);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement