Curl simulates login discuz program, suitable for DZ7.0, just change username to your username and userpass to your password.
/**
* Curl simulated login discuz program
* The forum login function with verification code enabled has not yet been implemented
*/
!extension_loaded('curl') && die('The curl extension is not loaded.');
$discuz_url = 'http://www.lxvoip.com';//Forum address
$login_url = $discuz_url .'/logging.php?action=login';//Login page address
$get_url = $discuz_url .'/my.php?item=threads'; //My posts
$post_fields = array();
//The following two items do not need to be modified
$post_fields['loginfield'] = 'username';
$post_fields['loginsubmit'] = 'true';
//Username and password, must be filled in
$post_fields['username'] = 'lxvoip';
$post_fields['password'] = '88888888';
//Security question
$post_fields['questionid'] = 0;
$post_fields['answer'] = '';
//@todo verification code
$post_fields['seccoverify'] = '';
//Get form FORMHASH
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
preg_match('/
/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}
//POST data, get COOKIE
$cookie_file = dirname(__FILE__) . '/cookie.txt';
//$cookie_file = tempnam('/tmp');
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
//Use the COOKIE obtained above to obtain the content of the page that needs to be logged in to view
$ch = curl_init($get_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
var_dump($contents);
?>
The above is the entire content of this article, I hope you all like it.
http://www.bkjia.com/PHPjc/954519.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/954519.htmlTechArticleIntroduction to PHP’s cURL library and its usage examples. This article mainly introduces the introduction and usage examples of PHP’s cURL library. It is required Friends can refer to using PHP's cURL library to easily and effectively capture web pages...