我得到了脚本的登录部分,但是第二部分不起作用。
<?php
// Curl login
$login = "http://****/admin/index.php?route=common/login";
$credentials = "username=admin&password=****";
$cookie = "cookie.txt";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $login);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $credentials);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$exec = curl_exec ($ch);
// Logged in, fetch the post data
$url = $_POST['order'];
$return = $_POST['return'];
// Request the protected invoice page
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
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_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail('****@gmail.com', 'Invoice', $response, $headers);
// Dump it
var_dump($response);
?>
现在,如果我提供了错误的凭据,那么我会收到带有登录错误的管理员登录页面,但是如果我提供正确的凭据,我只会收到一封空电子邮件。var_dump
在脚本结束时返回string(0)
.
如果登录管理,它是可访问的$url = $_POST['order'];
,它是一个正确的 URL,它会返回订单发票页面。
在尝试获取受保护的页面后,我是否应该重新初始化 curl。所以首先登录>关闭卷曲然后重新初始化并获取页面还是我错过了一些选项?
我的重申:
<?php
// Curl login
$login = "http://***/admin/index.php?route=common/login";
$credentials = "username=***&password=***";
$cookie = "cookie.txt";
// Initialize
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $login);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $credentials);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1)
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
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_HEADER, 0);
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
// Login - use
$exec = curl_exec ($ch);
// Logged in, fetch the post data
$url = $_POST['order'];
$return = $_POST['return'];
// Request the protected invoice page
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />';
var_dump($response);
echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />';
var_dump(curl_getinfo($ch));
echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />';
var_dump(curl_error($ch));
echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />';
echo $url;
echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />';
// Close the funnel
curl_close($ch);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail('***@gmail.com', 'Predracun', $response, $headers);
?>
这就是我现在拥有的,当我运行脚本时它给我一个 500 错误。