>백엔드 개발 >PHP 튜토리얼 >PHP本地CURL正常,但是放到SAE上后出现object moved to here

PHP本地CURL正常,但是放到SAE上后出现object moved to here

WBOY
WBOY원래의
2016-06-23 13:41:071986검색

login.php

<?php    error_reporting(E_ALL&~E_NOTICE);	set_time_limit(0);    include 'curlajax.class.php';   	//$proxy = "http://127.0.0.1:8087";    	//init curl&Agrave;&agrave;    $man = new curlajax();    $man->debug = 0;    $s = new SaeStorage();    $domain='sdlgdm';    $filename='/yzm/';    if($_POST['login']){        $url = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/Default2.aspx';        $data = '__VIEWSTATE='.urlencode($_POST['stat']).'&txtUserName='.urlencode($_POST['TextBox1']).'&TextBox2='.urlencode($_POST['TextBox2']).'&txtSecretCode='.urlencode($_POST['TextBox3']).'&RadioButtonList1='.urlencode('学生').'&Button1=&lbLanguage=&hidPdrs=&hidsc=';        $data = iconv("UTF-8", "GBK", $data);         $ch = curl_init();       // $proxy = "http://127.0.0.1:8087";		if($proxy){			echo 'proxy';            curl_setopt ($ch, CURLOPT_PROXY, $proxy);		}        curl_setopt($ch,CURLOPT_URL,$url);        curl_setopt($ch,CURLOPT_HEADER,1);        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);        curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.158888800.95 Safari/537.36 SE 2.X MetaSr 1.0");        curl_setopt($ch,CURLOPT_REFERER,$url);        curl_setopt($ch,CURLOPT_POST,1);        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);        /*        curl_setopt($ch,CURLOPT_HTTPHEADER,array (            'Proxy-Connection: keep-alive',            'Cache-Control: max-age=0',            'Origin: http://210.44.176.133',            'DNT: 1',        ));        */		echo '<pre class="brush:php;toolbar:false">';    		$Headers =  curl_getinfo($ch);		print_r($Headers);        $r = curl_exec($ch);        curl_close($ch);        print_r($r);//die;        $pre = 'http://210.44.176.134/';        $pat = "/Location:(.*)/i";        preg_match($pat,$r,$m);        $rurl = trim($m[1]);        print_r($rurl);        $rurl = $pre.''.substr($rurl,1);                //location        $r = $man->httpget($rurl,$url,0,array(),$proxy);        //file_put_contents('main.txt',$r);                $pre = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/';        $pat = '/<a href="(xskbcx[^"]*)"/i';        preg_match($pat,$r,$m);        echo "<br/>";                $infourl = trim($m[1]);        echo $infourl = $pre.''.$infourl;                    $r = $man->httpget($infourl,$rurl,0,array(),$proxy);        //file_put_contents('info.txt',$r);        echo $r;    }else{        //login        $url = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/Default2.aspx';        $r = $man->httpget($url,'',1,array(),$proxy);        $pat = "/Location:(.*)/i";        preg_match($pat,$r,$m);        $rurl = trim($m[1]);               //file_put_contents('loginpage.txt',$r);        //print_r($r);die; print_r($r);die;            //GET __VIEWSTATE        $pat = '/name="__VIEWSTATE" value="([^"]*)"/i';        preg_match($pat,$r,$m);        $stat = $m[1];                //GET vocde        $vocde_url = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/CheckCode.aspx';        $r = $man->httpget($vocde_url,$url,0,array(),$proxy);        $base=base64_encode($r);?><form action="" method="post"><input type="hidden" name="stat" value="<?php echo $stat;?>"/>x h:<input name="TextBox1" type="text" style="Width:130px" /><br />pwd:<input name="TextBox2" type="password" style="Width:130px" /><br />code:<input name="TextBox3" type="text"  style="Width:70px;color:#92a4bf" /><img   src="data:image/jpg;base64,<?php echo $base? alt="PHP本地CURL正常,但是放到SAE上后出现object moved to here" >"    style="max-width:90%" /><br /><input type="submit" name="login" value="submit"/></form><?php}?>


curlajax.class.php
<?phpclass curlajax{	public $ua;    public $debug;    	function __construct(){        $this->debug = 1;        $this->ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.158888800.95 Safari/537.36 SE 2.X MetaSr 1.0';	}        /****************************    *get 请求资源    *@param string 地址    *@param string referer    *@param boolen 是否返回头部    *@param array 头部附加cookie    ****************************/    function httpget($url,$referer='',$withhead=1,$httphead = array(),$proxy=''){        $ch = curl_init();        if($proxy){			curl_setopt ($ch, CURLOPT_PROXY, $proxy);		}		curl_setopt($ch,CURLOPT_URL,$url);		curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiejar);		curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);        curl_setopt($ch,CURLOPT_HEADER,$withhead);        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);        //curl_setopt($ch,CURLOPT_AUTOREFERER,1);		/*		curl_setopt($ch,CURLOPT_HTTPHEADER,array (            'Proxy-Connection: keep-alive',            'Cache-Control: max-age=0',            'Origin: http://210.44.176.133',            'DNT: 1',        ));		*/        curl_setopt($ch,CURLOPT_USERAGENT,$this->ua);        curl_setopt($ch,CURLOPT_REFERER,$referer);        $r = curl_exec($ch);        if($this->debug){            echo '<pre class="brush:php;toolbar:false">';            var_dump(curl_getinfo($ch));        }        curl_close($ch);        return $r;    }        /****************************    *post 请求资源    *@param string 地址    *@param string referer    *@param array 提交数据    *@param boolen 是否返回头部    ****************************/    function httppost($url,$referer='',$postdata=array(),$withhead=0,$httphead = array(),$proxy=''){        $ch = curl_init();		if($proxy){			curl_setopt ($ch, CURLOPT_PROXY, $proxy);		}        curl_setopt($ch,CURLOPT_URL,$url);        curl_setopt($ch,CURLOPT_HEADER,$withhead);        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);        //curl_setopt($ch,CURLOPT_AUTOREFERER,1);        curl_setopt($ch,CURLOPT_USERAGENT,$this->ua);        curl_setopt($ch,CURLOPT_REFERER,$referer);        curl_setopt($ch,CURLOPT_POST,1);        curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);        $r = curl_exec($ch);        if($this->debug){            echo '<pre class="brush:php;toolbar:false">';            var_dump(curl_getinfo($ch));        }        curl_close($ch);        return $r;    }}


在本地可以正常获取到相应的信息,可放到sae上后总是object moved to here,
SAE上在login.php第49行打印的信息中Location的值是 
Location:/(buoezbuq4apeu0v0151ruv55)/zdy.htm?aspxerrorpath=/xs_main.aspx;
而正常也就是在本地得到的正常值应该是 
Location: /(buoezbuq4apeu0v0151ruv55)/xs_main.aspx?xh=1011125007

小弟真心对curl中的一些东西了解甚少。。跪求论坛大牛们帮助。。。。
这是我sae上的测试地址:http://1.sdlgwx.sinaapp.com/lg/login.php测试账号:1011125007  密码111111


回复讨论(解决方案)

楼主,你的问题解决了么。。。我跟你是一样一样的问题。。。一模一样

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.