我想登录 fashiondays.ro 但出错。这是我的代码我尝试了很多脚本但我似乎无法让它工作......
当前脚本:
<?php
$loginUrl = 'https://www.fashiondays.ro/login_check/';
$email = 'thomanphan%40gmail.com';//demo user name
$password = '1234567890';//demo pass
$cookie_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "cookies.txt";
if (!file_exists($cookie_file))
{
$ourFileHandle = fopen($cookie_file, 'w') or die("can't open file");
fclose($ourFileHandle);
}
// make list of POST fields
$fields = array(
'_username' => urlencode($email),
'_password' => urlencode($password),
'_country_code' => urlencode('ro'),
'_remember_me' => urlencode('1')
);
$fields_string = '';
foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$ch = curl_init();
$headers = array(
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
"content-length: " . count($fields_string) //instead of 0, how could I get the
length of the body from curl?
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //set headers
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.fashiondays.ro/login/');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
if ($result === false) {
die('CURL ERROR: ' . curl_error($ch));
} else {
curl_setopt($ch, CURLOPT_URL, 'http://www.fashiondays.ro/campaigns/');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if ($result === false) {
die('CURL ERROR: ' . curl_error($ch));
} else {
echo $result;
}
}
?>