-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.php
More file actions
102 lines (99 loc) · 2.77 KB
/
common.php
File metadata and controls
102 lines (99 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
date_default_timezone_set("Asia/Jakarta");
$uniqid = uniqid();
function logit($str){
global $uniqid;
if(!is_dir("logs")){
mkdir("logs");
}
$logfile = date('Ymd').".log";
$log = fopen("logs/$logfile","a");
$write = date('Y-m-d H:i:s')." - ".$uniqid." - ".get_client_ip()." - ".$str."\n";
fwrite($log, $write);
fclose($log);
}
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
function isjson($string){
return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
}
function is_xml($xml){
$doc = @simplexml_load_string($xml);
if ($doc) {
return true; //this is valid
} else {
return false; //this is not valid
}
}
function arr2xml($arr,$root="response") {
$xml = "<".$root.">";
foreach ($arr as $key => $value) {
if(is_array($value)) {
$xml.=arr2xml($value,$key);
} else {
$xml .= "<$key>$value</$key>";
}
}
$xml .= "</".$root.">";
return $xml;
}
function curlPost($url,$param){
$ch = curl_init();
if($ch==false){
die('Failed to create curl object');
}
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $param);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
//execute post
$result = curl_exec($ch);
$err = curl_error($curl);
//close connection
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $result;
}
}
function curlGet($url){
$ch = curl_init();
if($ch==false){
die('Failed to create curl object');
}
// $timeout = 40;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
curl_close($ch);
// unset($ch);
return $data;
}
$ret["nol"]="0";
$ret["satu"]["dua"]="01";
$ret["tiga"]["empat"]["lima"]="012";
$ret["tiga"]["empat"]["enam"]="013";
$ret["empat"]="4";
logit(arr2xml($ret));
?>