使用PHP& Curl登录我的网站表单 [英] Using PHP & Curl to login to my websites form

查看:126
本文介绍了使用PHP& Curl登录我的网站表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图登录到我的用户帐户,我使用从网站下载文件,所以我可以自动抓取该文件, strong>这是以下形式:

 < form method ='post'action ='/ news.php '> 
< div>
用户名:< input class ='tbox'type ='text'name ='username'size = '15'value =''maxlength = '20'/>& nbsp;& nbsp;
密码:< input class ='tbox'type ='password'name ='userpass'size = '15'value =''maxlength = '20'/>& nbsp;& nbsp;
< input type ='hidden'name ='autologin'value ='1'/>
< input class ='button'type ='submit'name ='userlogin'value ='Login'/>
< / div>
< / form>

这里是迄今为止的PHP。 b
$ b

 <?php 
$ username =my_user;
$ password =my_passs;
$ url =the_url;
$ cookie =cookie.txt;

$ postdata =username =。$ username。& userpass =。$ password;

$ 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,0);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_COOKIEJAR,$ cookie);
curl_setopt($ ch,CURLOPT_REFERER,$ url);

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

echo $ result;
curl_close($ ch);
?>

我做错了什么?



感谢

解决方案

您应该通过POST发送orignal表单发送的所有数据。因此,您在 $ postdata 中缺少 autologin = 1& userlogin = Login

  $ postdata =username = $ username& userpass = $ password& autologin = 1& userlogin = Login; 


Im trying to login to my useraccount on a site i use to download files from so i can automatically grab the file without me having to visit the site.

This is the form:

 <form method='post' action='/news.php'>
 <div>
             Username: <input class='tbox' type='text'     name='username' size='15' value='' maxlength='20' />&nbsp;&nbsp;
             Password: <input class='tbox' type='password' name='userpass' size='15' value='' maxlength='20' />&nbsp;&nbsp;
             <input type='hidden' name='autologin' value='1' />
             <input class='button' type='submit' name='userlogin' value='Login' />
 </div>
 </form>

Here is the PHP ive got so far.

<?php
$username="my_user"; 
$password="my_passs"; 
$url="the_url"; 
$cookie="cookie.txt"; 

$postdata = "username=".$username."&userpass=".$password; 

$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, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

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

echo $result;  
curl_close($ch);
?>

Am i doing something wrong? It just displays the website at the moment but doesn't log me in. Ive never used Curl before.

Thanks

解决方案

You should send via POST all data that the orignal form is sending. So you are missing autologin=1&userlogin=Login in your $postdata.

$postdata = "username=$username&userpass=$password&autologin=1&userlogin=Login";

这篇关于使用PHP&amp; Curl登录我的网站表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆