标签:cli lod ret tip 常用 fun remote str ===
/**
* CURL方法
* @param type $url
* @param type $https
* @param type $method
* @param type $data
* @return type
*/
public function request($url, $https = true, $method = ‘get‘, $data = null)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($https === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if ($method == ‘post‘) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$str = curl_exec($ch);
curl_close($ch);
return $str;
}
/**
* 对象 转 数组
* @param object $obj 对象
* @return array
*/
public function objToArr($object)
{
$object = json_decode(json_encode($object), true);
return $object;
}
/**
* 获取客户端ip
* @return string 客户端ip地址
* @author lichuang
*/
public function getIp()
{
$ip = false;
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR‘])) {
$ips = explode(",", $_SERVER[‘HTTP_X_FORWARDED_FOR‘]);
if ($ip) {
array_unshift($ips, $ip);
$ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++) {
if (!eregi("^(10|172\.16|192\.168)\.", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER[‘REMOTE_ADDR‘]);
}
标签:cli lod ret tip 常用 fun remote str ===
原文地址:https://www.cnblogs.com/zhengkk/p/11944128.html