首页 > 代码库 > Curl函数
Curl函数
<?phpdefine(‘ROUTE_ROOT‘,‘‘);define(‘ROUTE_PASSWORD‘,‘‘);define(‘ROUTE_URL‘,‘‘);define(‘COOKIE_FILE‘,‘cookie_file.txt‘);define(‘TiYanShiJian‘,‘30‘);define(‘ADMIN_PHONE‘,‘0571-83055016‘);$time=time();$ddate=$time+TiYanShiJian*60;header("Content-Type:text/html;charset=UTF-8");//require("config.php");//封装登陆函数function curl_tijiao($tijiao_url,$zhuce_data,$access,$callback){ $cookie_file = dirname(__FILE__).‘/‘.COOKIE_FILE; $post_fields = ‘user=‘.ROUTE_ROOT.‘&password=‘.ROUTE_PASSWORD; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $tijiao_url); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[‘HTTP_USER_AGENT‘]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($access==true){ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($zhuce_data)); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); } curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $return = curl_exec($ch); $tishi_json = iconv("GB2312","UTF-8",$return); //var_dump($zhuce_url); //var_dump($post_fields); curl_close($ch); if (strpos($tishi_json,‘{pppoe_client‘) !== false) { //return $tishi_json; echo $callback."({ret:0,msg:‘亲,你别看!行么?‘})"; }else if (strpos($tishi_json,‘{err‘) !== false) { echo $callback.‘(‘.$tishi_json.‘)‘; }else{ if ($access==true){ $login_url = ROUTE_URL.‘login.cgi‘; $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_exec($ch); curl_close($ch); } //return error_msg(‘路由连接失败!‘); echo $callback."({ret:1,msg:‘参数错误!或没有申请到key!支持Ajax跨域提交!详细QQ:264059790‘})"; } //curl_close($ch);}//封装登陆函数结束//开始获取参数$callback = isset($_REQUEST[‘callback‘]) ? trim($_REQUEST[‘callback‘]) : ‘‘;$Mob = isset($_REQUEST[‘Mob‘]) ? trim($_REQUEST[‘Mob‘]) : ‘‘;$realname="zhouein";$cellphone="0571-83055016";$mem="beizhu>>".$realname.">>".$cellphone;$tijiao_url=ROUTE_URL.‘/user.asp‘;$zhuce_data = array( ‘user‘ => ‘15336500025‘, ‘pwd‘ => ‘15336500025‘, ‘ddate‘ => ‘1479138600‘, ‘mem‘ => ‘beizhu>>zhouein>>83055016‘, ‘num‘ => ‘1‘, ‘vlan‘ => ‘0‘, ‘state‘ => ‘96‘, ‘gid‘ => ‘0‘, ‘speed_mode‘ => ‘dl‘, ‘speed_up‘ => ‘20‘, ‘speed_down‘ => ‘500‘, ‘mod_pwd‘ => ‘0‘, ‘opt‘ => ‘add‘, ); $zhuce_data[‘user‘]=$Mob; $zhuce_data[‘pwd‘]=$Mob; $zhuce_data[‘mem‘]=$mem; $zhuce_data[‘ddate‘]=$ddate; $zhuce_data[‘_‘]=$time; $return = curl_tijiao($tijiao_url,$zhuce_data,true,$callback);?>
客户端
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Ajax Jsonp</title> <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script> </head> <script type="text/javascript"> $(function(){ $.ajax({ type : "GET", async:false, url : "http://www.zhouein.com/wayos_api/function.php", dataType : "jsonp", data:{ Mob:"15967128951", mykey:"222", mystr:"ggg" }, jsonp: "callback", jsonpCallback:"zhouein", success : function(data){ $("#showcontent").text(data.msg) $("#showcontent").text(data.err) }, error:function(){ alert(‘no!‘); } }); }); </script> <body> <div id="showcontent">ddddddddddddddddddd:</div> <!--http://115.236.183.115:81/php_encode/?act=ENCODE&mykey=222&mystr=ggg&callback=kkkk--> </body> </html>
Curl函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。