首页 > 后端开发 > php教程 > php之curl学习_PHP教程

php之curl学习_PHP教程

WBOY
发布: 2016-07-13 09:44:46
原创
1230 人浏览过

php之curl学习

幸好CTO 给我写好了一个范例 偷偷保存下来 以后就照着这个写 吐舌头
<!--?php 

	test_put();

	function test_put() {
	   $data = array(id =--> 3, name => peter, age => 67);
	   $data = Authorize_check($data);
	   //print_r($data);exit;
	   $data_string = $data;
	   //$token = base64_encode(admin:1234);
	   $ch = curl_init(&#39;http://localhost/demo/index.php/member/post&#39;);
	   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);
	   curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	       &#39;X-HTTP-Method-Override: POST&#39;)
	   );
	   $result = curl_exec($ch);
	   print_r($result);exit;
	   $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	   $contenttype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
	   print Status: $httpcode . 
;
	   print Content-Type: $contenttype . 
;
	   print 
. $result . 
;
	}

	function Authorize_check($data){
		if (is_array($data)) {
			$chdata=&#39;&#39;;
			ksort($data);
			//var_dump($data);exit;
			foreach($data as $key => $val) {
                if ($key==&#39;contact&#39; || $key==&#39;condition&#39; || $key==&#39;from&#39;)
                {
                    continue;
                }
				if($key==&#39;usersession&#39; && empty($data[&#39;usersession&#39;])){
					$data[&#39;usersession&#39;]=&#39;&#39;;
				}
				if($key != &#39;chdata&#39;){
					$chdata.=$key.&#39;=&#39;.$val.,;
				}
				
			}                      
			$chdata=trim($chdata,,);
        		
			$chdata=md5($chdata.jiamizifuchuan);
			$data[&#39;chdata&#39;] = $chdata;
			return $data;
		}
	}

//list($username, $password) = explode(&#39;:&#39;, base64_decode(substr(&#39;Basic YWRtaW46MTIzNA==&#39;, 6)));
//echo $username;

?>
登录后复制

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1047181.htmlTechArticlephp之curl学习 幸好CTO 给我写好了一个范例 偷偷保存下来 以后就照着这个写 3, name = peter, age = 67); $data = Authorize_check($data); //print_r($data);exit...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板