[英]Login to a site using PHP and CURL
对我来说,唯一的问题是它没有用于表单提交的html按钮,而是使用没有名称属性的css样式的自定义按钮。 这是表格
<form name="login_form" method="post" action="index.php" onsubmit="loginFormSubmit(this)">
<div style="position:absolute;top:-1500px;"><input type="submit" value="sub"></div>
Username:<input name="username" size="20" maxlength="32"><br><br>
Password:<input type="password" name="passwd" size="20" maxlength="32">
</form>
Button的HTML代码,如果在标记之外
<div style="position: absolute; width: 54px; height: 20px; top: 382px; margin-left: 312px; cursor: pointer; color: rgb(255, 255, 255); font-style: normal; font-weight: normal;" onmouseover="fFOB(this)" onmouseout="fFNN(this)" onclick="loginFormSubmit(document.login_form)">Login</div>
这是我的PHP代码
<?php
$username="yyyyy";
$password="xxxxx";
$url="http://example.com/login.php";
$cookie="cookie.txt";
$postdata = "username=".$username."&passwd=".$password;
$postdata = "username=$username&passwd=$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);
?>
更改类型,例如
method = 'get'
在表单标签和php代码中使用
GET['username'],GET['password']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.