我使用HttpFox并将值(url和post数据)与我的代码生成的值进行了比较。它们是完全相同的,但我总是看到消息“登录失败”#39;在网页上。我不知道会出现什么问题。
代码:
require 'domparser_1_5/simple_html_dom.php';
$username = "username";
$password = "password";
function login($url,$data){
$fp = fopen("cookie.txt", "w");
fclose($fp);
$login = curl_init();
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 40000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, true);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($login, CURLOPT_POST, true);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec($login);
ob_end_clean();
curl_close($login);
unset($login);
}
function generate_pass($user, $password) {
$token = get_token();
if ($password) {
$enc_pass = md5($password);
$pass = $user.':'.$enc_pass.':'.$token;
return md5($pass);
}
}
function get_token() {
$html = file_get_html('https://www.foo.com/');
$token = "";
foreach($html->find('input') as $element) {
if($element->name == "token") {
$token = $element->value;
}
}
if (!$token) {
die('No token found');
}
return $token;
}
echo login("https://www.foo.com/login/start.html", "user=".$username."&password=".$password."&submit=Anmelden&logintype=login&pid=4%2C93%2C1828&pass=".generate_pass($username, $password)."&redirect_url=login%2Fstart.html&tx_felogin_pi1%5Bnoredirect%5D=0&token=".get_token()."");
你能帮帮我吗?