我有一个代码登录到网站。它在像wordpress这样的网站上工作,但在我想登录的网站上什么也没有发生。其中没有错误消息或任何内容。下面是我的代码:
<?php
print" <head>
<base href='http://www.example.com/'/>
</head>";
$url = 'http://www.example.com/login.php?';
$postdata = 'username=dasds&password=frkm';
$referer = $url;
$cookie = "cookie.txt" ;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
curl_setopt($ch,CURLOPT_COOKIESESSION,false);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
print $result;
curl_close($ch);
?>和它们的html格式:
<form name="form" method="post" action="/login.php">
<label class="registration" for="username">
<span>Username</span>
<input name="username" type="text" id="username" size="30"/>
</label>
<label class="registration" for="password">
<span>Password</span>
<input name="password" type="password" id="password"/>
</label>
<input type="submit" name="Login" value="Login"/>
</form>发布于 2012-10-29 04:24:08
尝试此
COOKIEJAR和COOKIEFILE,并设置cookie文件的绝对路径:代码
curl_setopt ($ch, CURLOPT_COOKIEJAR, __DIR__.'/'.$cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, __DIR__.'/'.$cookie);和:
如果你在浏览器中跟踪登录请求+响应,你就不会失败。
https://stackoverflow.com/questions/13112630
复制相似问题