To simulate login in PHP, we need to use the curl_init function. Next, I will introduce how to use curl to simulate post login to the discuz forum and implement the automatic post function.
In fact, simulating login is just a matter of getting the corresponding parameters, then simulating sending, and bringing the obtained COOKIE into the next step
In order to prevent flooding, the discuzx series has been using the formhash() function:
1. Let’s take a look at the formhash function:
The code is as follows | Copy code | ||||
global $_G; |
5. hashadd(fixed value) 6. specialadd(fixed value) Because there is a user name and user id, the values generated before logging in and after logging in are different, that is: you have to get fromhash twice before logging in and after logging in;
So what is authkey?
代码如下 | 复制代码 |
if(empty($this->var['cookie']['saltkey'])) { $this->var['cookie']['saltkey'] = random(8);//这一步不要去管 dsetcookie('saltkey', $this->var['cookie']['saltkey'], 86400 * 30, 1, 1); } $this->var['authkey'] = md5($this->var['config']['security']['authkey'].$this->var['cookie']['saltkey']); |
//Code location:/source/class/discuz/discuz_application.php
The code is as follows | Copy code |
if(empty($this->var ['cookie']['saltkey'])) { $this->var['cookie']['saltkey'] = random(8);//Don't worry about this step dsetcookie('saltkey', $this->var['cookie']['saltkey'], 86400 * 30, 1, 1); } $this->var['authkey'] = md5($this->var['config']['security']['authkey'].$this->var['cookie']['saltkey ']);
|
代码如下 | 复制代码 |
$this->var['config']['cookie']['cookiepre'] = $this->var['config']['cookie']['cookiepre'].substr(md5($this->;var['config']['cookie']['cookiepath'].'|'.$this->;var['config']['cookie']['cookiedomain']), 0, 4).'_'; |
As long as you log in to the website and look at the cookie settings, it will be fine. The prefix hi will indeed remain unchanged. Of course, it will definitely change if the configuration file is changed
How should I write it: Let me talk about my idea of implementation
1. After logging in, visit the website and grab the saltkey (cookie) and formhash (value) returned by the web page (saltkey must be brought below, and the context must be consistent)
2. Construct the login content and then simulate post submission (be sure to bring the cookie and formhash value captured in the first step)
3. If the login is successful, then obtain the formhash of a page and the set cookie (the formhash obtained this time is what you can always use)
4. Construct posts and top posts and submit them to the page (cookies and formhash are still important)
About php using crul to simulate post part of the code
The code is as follows
|
Copy code
|
||||
$ch = curl_init($url); //Initialization |
curl_setopt($ch,CURLOPT_REFERER,$refer);
http://www.bkjia.com/PHPjc/629893.html