This time we talk about the commit module.
In the process of browsing the Web before writing this article, I have seen some discussion about the legality and morality of VJ, but I won't talk about it in this article, we only care about technology.
We are committing with PHP, so we have to use one thing: curl. However, PHP is not enabled by default Curl support, no matter how you use, in short, let him work up, not to say, direct code:
Public Function Poj_dataposter_worker ($user = "skvj01", $pass =
"Forskvj", $id = "$", $lang = "0", $code = "", $rid = "") {
if (DEBUG)
echo "[D] = $user, $pass, $id, $lang, $rid \ n"; MySQL $this->db = new Dmysql (); Infomation $cookie _file =
Tempnam ("./cookie", "Cookie"); $login _url = "Http://poj.org/login";
$post _fields = "user_id1=". $user. " &password1= ". $pass." &url=/";
$this->rid = $rid; $this->pid = $id; $this->lang = $lang;
$this->user = $user; $this->pass = $pass;
Login $curl = curl_init ($login _url);
curl_setopt ($curl, Curlopt_header, 0); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_cookiejar,
$cookie _file); curl_setopt ($curl, Curlopt_post, 1);
curl_setopt ($curl, Curlopt_postfields, $post _fields);
$this->data = curl_exec ($curl); Curl_close ($curl);
Submit $hint _code =/"//". $rid. " \ n "./$code; $post _fields =
' problem_id= '. $id. ' &language= '
. $lang. ' &encoded=1&source= '. UrlEncode ($hint _code);
Print_r (Base64_encode ($code)); $curl =
Curl_init ("Http://poj.org/submit");
curl_setopt ($curl, Curlopt_header, 0); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_cookiefile,
$cookie _file); curl_setopt ($curl, Curlopt_post, 1);
curl_setopt ($curl, Curlopt_postfields, $post _fields);
$this->data = curl_exec ($curl); Curl_close ($curl);
@unlink ($cookie _file);
Record information $this->info = Array (
' id ' = $rid,
' User ' = $user
);
}
Here or use POJ as an example, POJ submitted immediately after the record will be generated, and hdoj and so on, this is the use of curl simulation submitted a bit.
$PDW = new Poj_dataposter_worker ($oo _u, $oo _p, $list [$i] [' Tid '],
$list [$i] [' Lang '], $list [$i] [' Code '], $list [$i] [' id ']); $rrid =
$PDW->getrunid ()
This creates the instance and commits the code, and then gets the Runid, which is the remote record ID. The above mentioned will produce a record after the submission, this is better, the quick direct crawl is good. Of course, the crawl is not the commit error, there is no following. Of course, crawling to, is a dead loop, constant query status, and then update the local record on it.
The above mentioned crawl, there is a problem, is how to determine which record is your current submission of the record, this has the following scheme:
1. An account is a separate queue, one for each submission;
2. Each query only inquires the records submitted by this account, not all;
3. Annotate the code with an absolute ID that is used to crawl all source codes and match.
Here 3 is theoretically superfluous for the first two, as long as you catch the one. However, because each time is to crawl a page, so the way to add this mechanism, insurance is the most important.
Article published: May 4th at 01:31 pm
Last modified: 4th at 01:55 pm
This article was authored by Springhack and licensed by the Creative Commons Attribution 4.0 International license
may be freely reproduced, quoted, but must be signed by the author and indicate the source of the article