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

查看:32
本文介绍了使用 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'/>

</表单>

这是我目前得到的 PHP.

我做错了吗?它目前只显示网站,但不会让我登录.我以前从未使用过 Curl.

谢谢

解决方案

您应该通过 POST 发送原始表单正在发送的所有数据.因此,您的 $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;卷曲以登录我的网站表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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