我正在尝试编写一个脚本,该脚本将允许我登录到在 zencart 上运行的站点的密码保护区域并以字符串形式获取 html。到目前为止,它下载了 HTML 页面,作为 .html 文件,但只是页面的公共版本(即它没有成功登录)。它是 HTTPS,我相信这可能是它无法正常工作的部分原因。我的脚本有什么问题我需要什么 CURL 设置(遗憾的是,关于 PHP 的 CURL 的文档很少:()
<?php
$username = "xxxx@gmail.com";
$password = "xxxxx";
$securityToken = "b6afe5babdd1b6be234d1976586fb1f1";
$loginUrl = "https://www.xxxxxxx.com.au/index.php?main_page=login&action=process";
//init curl
$ch = curl_init();
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email_address='.$username.'&password='.$password.'&securityToken='.$securityToken);
//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie122.txt');
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute the request (the login)
$store = curl_exec($ch);
//the login is now done and you can continue to get the
//protected content.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'http://www.xxxxxxx.com.au/index.php?main_page=product_info&products_id=1488');
//execute the request
$content = curl_exec($ch);
//save the data to disk
file_put_contents('test122.html', $content);
if(curl_error($ch)) {
$error = curl_error($ch);
echo $error;
}
?>