跨域访问PHP代理解决方案

来源:互联网 发布:网络教育有研究生 编辑:程序博客网 时间:2024/04/29 20:31

示例说明:
    其中:http://203.156.244.227:80/cgi-bin/get_score.fcgi为要代理的URL,参数为content正文内容。

GET方法代理:
<?php$searchUrl = 'http://203.156.244.227:80/cgi-bin/get_score.fcgi?content=';if(!empty($_GET['content'])){$searchUrl .= $_GET['content'];}echo file_get_contents($searchUrl);?>

POST方法代理:
<?php$post_string = "content=".$_POST['content'];echo request_by_post('http://203.156.244.227:80/cgi-bin/get_score.fcgi',$post_string);function request_by_post($remote_server,$post_string){$context = array('http'=>array('method'=>'POST','header'=>'Content-type: application/x-www-form-urlencoded'."\r\n".'User-Agent : Firstboy\'s POST Example beta'."\r\n".'Content-length: '.strlen($post_string)+1,'content'=> $post_string));$stream_context = stream_context_create($context);$data = file_get_contents($remote_server,FALSE,$stream_context);return $data;}?>



原创粉丝点击