PHP中文网2017-02-08 09:16:00
使用jsonp接口的方式输出数据,也可以在服务器端加上允许域名来源设置,代码如下:
<?php $origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : ''; $allow_origin = array( 'http://php.cn', 'http://www.php.cn', 'http://m.php.cn', ); if(in_array($origin, $allow_origin)){ header('Access-Control-Allow-Origin:'.$origin); }
巴扎黑2017-02-07 13:51:33
function https_request($url,$data = null){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }