使用PHP& Curl登录我的网站表单

编程入门 行业动态 更新时间:2024-10-28 18:24:31
本文介绍了使用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登录我的网站表单

本文发布于:2023-06-05 01:10:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/508775.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   网站   PHP   amp   Curl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!