字符串转时间戳

function str_time($strtime){
    $backtime = strtotime(date('Y-m-d',time()));
    if(strpos($strtime,':') !== false){ 
        $strtime = trim($strtime);
        $timenow = time();
        $nowday = strtotime(date("Y-m-d")." ".$strtime.":00");
        if($nowday<=$timenow){
            return $nowday==false?$backtime:$nowday;
        }else{
            $yestime = strtotime(date("Y-m-d",strtotime("-1 day"))." ".$strtime.":00");
            return $yestime==false?$backtime:$yestime;
        }
    }else{
        return $backtime;
    }
}

获取访客ip

function getIp() {
    if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
        $ip = getenv("HTTP_CLIENT_IP");
    else
    if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    else
    if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
        $ip = getenv("REMOTE_ADDR");
    else
    if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
        $ip = $_SERVER['REMOTE_ADDR'];
    else
        $ip = "unknown";
    if(strpos($ip,',') !== false)
    {
            $arr = explode(',',$ip);
            $ip=$arr[0];
    }
    $ip=str_replace("<","",$ip);
    $ip=str_replace(">","",$ip);
    $ip=str_replace("/","",$ip);
    $arr = explode('.',$ip);
    if(count($arr) != 4){
         $ip="xss";
    }else{
        for($i = 0;$i < 4;$i++){
            if(($arr[$i] <0) || ($arr[$i] > 255)){
                 $ip="xss";
            }
        }
    }
    return ($ip);
}

百度api回传ocpc

function bdocpcapi($token, $conversionTypes){
    $BAIDU_OCPC_URL = 'https://ocpc.baidu.com/ocpcapi/api/uploadConvertData';
    $RETRY_TIMES = 3;
	$reqData = array('token' => $token, 'conversionTypes' => $conversionTypes);
    $reqData = json_encode($reqData);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_URL, $BAIDU_OCPC_URL);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $reqData);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8','Content-Length: ' . strlen($reqData)));
	for ($i = 0; $i < $RETRY_TIMES; $i++) {
		$response = curl_exec($ch);
		$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		if ($httpCode === 200) {
			// 打印返回结果
			// do some log
			//print_r('retry times: ' . $i . ' res: ' . $response . "\n");
			$res = json_decode($response, true);
			// status为4,代表服务端异常,可添加重试
			$status = $res['header']['status'];
			if ($status !== 4) {
				curl_close($ch);
				return $status;
			}
		}
	}
        curl_close($ch);
        return false;
    }