-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