-1
當我執行localhost中的腳本時,工作正常。但爲什麼腳本不能在web服務器上工作?curl在服務器上不起作用,但在本地主機上正常工作
**爲了讓我發佈一些東西,我需要寫多少? 「看起來你的文章主要是代碼,請添加更多的細節。」
這是我的代碼
<?php
date_default_timezone_set("Asia/Jakarta");
//identity
$user = "test_bot";
$pass = "test123";
//general data
$ua = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31";
$url_login = "http://devilzc0de.org/forum/index.php";
$url_post = "http://devilzc0de.org/forum/xmlhttp.php";
$url_smiles = "http://devilzc0de.org/forum/misc.php?action=smilies&popup=true&editor=clickableEditor";
//data to be sent
$data = array(":logodc", ":sungkem", ":metal", ":cambuk", ":garing", ":hah", ":army");
$smiles = smiles($url_smiles, $ua);
$post = $data[rand(0, count($data)-1)]." ".$smiles[rand(0, count($smiles)-1)];
//call function of login and send data
login($url_login, $user, $pass, $ua);
$send = post($url_post, $post, $ua);
//write logs
$logs = $user.": ".date("H:i:s d-m-Y")."-->".$post."-->".$send."\n";
$fp = fopen("logs.txt", "a");
fwrite($fp, $logs);
echo $logs;
function login($url_login, $user, $pass, $ua){
$data = array("action" => "do_login", "username" => $user, "password" => $pass, "loginsubmit" => "Login!");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_login);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, "kookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "Kookie.txt");
$exec = curl_exec($ch);
curl_close($ch);
return $exec;
}
function smiles($url_smiles, $ua){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_smiles);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "kookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "Kookie.txt");
$exec = curl_exec($ch);
$remove_html = strip_tags($exec);
$pecah = explode("Click a smilie to insert it into your message", $remove_html);
$hapus = str_replace(array("[", "]", "close window", "\n", "\r", "\r\n"), " ", $pecah[1]);
$hapus2 = preg_replace("/\s+/", " ", $hapus);
$smiles = explode(" ",trim($hapus2));
curl_close($ch);
return $smiles;
}
function post($url_post, $post, $ua){
$data = array("action" => "add_shout", "shout_data" => $post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_post);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, "kookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "Kookie.txt");
$exec = curl_exec($ch);
curl_close($ch);
return $exec;
}
?>
是否只是捲曲cookie的問題..?
嗷嗷,我已經取代「kookie.txt」到「/tmp/kookie.txt」和它的工作 – RieqyNS13 2013-04-07 06:04:11
檢查是否已安裝在服務器中捲曲。 – 2013-04-07 06:09:03