顧客向けの DLE オートポスターに取り組んでいます。私はこのコードを書きました:
function postit($url, $postdata ="", $header = false, $follow = 0, $headers = "") {
global $cookie;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.downgiga.com/addnews.html");
if($header == true) {
curl_setopt($ch, CURLOPT_HEADER, 1);
}
if($headers != "") {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd() . '/' . $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd() . '/' . $cookie);
$log = fopen(getcwd() . '/' . 'log.txt', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $log);
if($follow <> 0) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
if($postdata <> "") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
$source_code = curl_exec($ch);
curl_close($ch);
return $source_code;
}
$cookie = "cookies";
//login
$post['login_name'] = "joker";
$post['login_password'] = "123123";
$post['login'] = "submit";
$page = postit("http://www.downgiga.com/addnews.html", $post);
unset($post);
$secpattern = '/<input type="hidden" name="([a-z]*)" value="([a-z0-9]*)" \/><\/form>/';// some security
preg_match($secpattern, $page, $match);// some security
if($match) $post[$match[1]] = $match[2];// some security
$post['title'] = "test";
$post['catlist'] = '2';
$post['short_story'] = "short test";
$post['full_story'] = "full test";
$post['tags'] = "full,test";
$post['add'] = "Submit";
$post['mod'] = "addnews";
$post['nview'] = "Preview";
$post['allow_comm'] = true;
$post['allow_main'] = false;
$post['approve'] = true;
$post['allow_rating'] = true;
$headers = array('Content-Type: application/x-www-form-urlencoded');
echo postit("http://www.downgiga.com/addnews.html", $post, false, 0, $headers);
そして、それは私にこのエラーを与えます
ANTISPAM: User ID not valid
さて、これは成功した投稿でGoogle Chromeから抽出されたcurlログとhttpヘッダーです。
CURLログ
* About to connect() to www.downgiga.com port 80 (#0)
* Trying 109.232.224.104... * connected
* Connected to www.downgiga.com (109.232.224.104) port 80 (#0)
> POST /addnews.html HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)
Host: www.downgiga.com
Accept: */*
Referer: http://www.downgiga.com/addnews.html
Cookie: dle_password=4297f44b13955235245b2497399d7a93; dle_user_id=108; dle_newpm=0
Content-Length: 1386
Content-Type: multipart/form-data; boundary=----------------------------993bf2bec865
< HTTP/1.1 200 OK
< Date: Thu, 25 Aug 2011 23:49:10 GMT
< Server: Apache/2.2.17 (EL)
< X-Powered-By: PHP/5.2.17
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
* Added cookie PHPSESSID="42104e9342c70e8db167f417f6484a2d" for domain www.downgiga.com, path /, expire 0
< Set-Cookie: PHPSESSID=42104e9342c70e8db167f417f6484a2d; path=/
* Replaced cookie dle_newpm="0" for domain downgiga.com, path /, expire 1345852151
< Set-Cookie: dle_newpm=0; expires=Fri, 24-Aug-2012 23:49:11 GMT; path=/; domain=.downgiga.com; httponly
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
* Closing connection #0
Google Chrome http ヘッダー
POST /addnews.html HTTP/1.1
Host: www.downgiga.com
Connection: keep-alive
Content-Length: 223
Cache-Control: max-age=0
Origin: http://www.downgiga.com
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.861.0 Safari/535.2
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://www.downgiga.com/addnews.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: PHPSESSID=99de9359543b04cc43fb887fc64f7ff9; selected_language=English; dle_user_id=108; dle_password=4297f44b13955235245b2497399d7a93; dle_newpm=0
Google Chrome から取得したデータも投稿する
title:test2
short_story:<p>test :)</p>
full_story:<p>testing headers :)</p>
tags:test header
allow_comm:1
approve:1
allow_rating:1
add:Submit
mod:addnews
uxfpekxs:92006af0832447ad34fdaa8328ac788b
投稿データの最後の行はセキュリティに関するもので、毎回変更されます。また、カールハンドルからカスタムヘッダーを削除しようとしましたが、何も変わりません:(