Remote Login not Working With Curl

∥☆過路亽.° 提交于 2019-12-25 01:44:51

问题


hi i have remote login code and try connect to my Target site but i cant .

$url="http://hipfile.com"; 

$postdata = "login=bnnoor&password=########&op=login";

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

if (!$result) { 
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
        curl_close($ch); // make sure we closeany current curl sessions 
        die($http_code.' Unable to connect to server. Please come back later.'); 
    } 
echo $result;  
curl_close($ch);

and login form in site is

    <form method="POST" action="http://hipfile.com/" name="FL">

<input type="hidden" name="op" value="login">
<input type="hidden" name="redirect" value="http://hipfile.com/">
<div class="clear span-5">Username:&nbsp;<input type="text" name="login" value="bnnoor" class="myForm"></div>
Password:&nbsp;<input type="password" name="password" class="myForm">
<input type="image" style="height: 34px; padding-left:10px; padding-bottom: 3px; vertical-align: middle;" src="http://hipfile.com/images/login.png">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://hipfile.com/?op=forgot_pass">Forgot your password?</a><br>

</form>

but i cant access my file in site and after start page redirect to login page in site? plz help me .


回答1:


A. Invalid Url

you are using http://hipfile.com which would return HTTP/1.1 500 - Bad Response

What you need to use is (Note the / at the end )

 $url = "http://hipfile.com/" ;

B. Invalid Referrer

You also need to change CURLOPT_REFERER to http://hipfile.com/login.html




回答2:


Just to check, do a GET on the login page and store the set cookie with value. use that cookie along with your post.

Also, send the redirect hidden field along with your post variables




回答3:


setup CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR, you will keep cookie when next connect

http://php.net/manual/en/function.curl-setopt.php



来源:https://stackoverflow.com/questions/10546701/remote-login-not-working-with-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!