public function getTask() { $objtask = new Model('project'); $alltask = $objtask->field('project_hash,target,setting')->where("status = 0")->find(); //处理exp数组 if ($alltask) { $arr = array_merge($alltask, unserialize($alltask['setting'])); unset($arr['setting']); //格式化与加密数据 //echo str_replace("\\/","/",json_encode($arr)); echo data_encode(str_replace("\\/", "/", json_encode($arr)), $this->key); } else { echo 'notask'; } }
function Curl_Page($path) { // $path - страничка, какую смотрим global $agent, $header, $referer, $arr_cookie, $cookie_file; // вызываем сеанс Curl $ch = curl_init($path); // CURL будет возвращать результат, а не выводить его в печать curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // выводим подробные сообщения о всех действиях curl_setopt($ch, CURLOPT_VERBOSE, 0); //1 // считываем страничку с хедером от сервера //curl_setopt ( $ch , CURLOPT_HEADER , 1 ); // отправим серверу user_agent сформированный нами самими curl_setopt($ch, CURLOPT_USERAGENT, $agent); // оправляем $referer, что пришли с первой страницы сайта curl_setopt($ch, CURLOPT_REFERER, $referer); // оправляем на сервер хедер, который мы сами сформировали //curl_setopt ( $ch , CURLOPT_HTTPHEADER , $header ); // при получении HTTP заголовка "Location: " будет // происходить перенаправление curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // запретить проверку сертификата удаленного сервера curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // не будем проверять существование имени curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // если есть массив с cookie, то отправим серверу, эти cookie if (@is_array($arr_cookie)) { while (list($key, $val) = @each($arr_cookie)) { $COKKIES .= trim($val[0]) . "=" . trim($val[1]) . "; "; } @curl_setopt($ch, CURLOPT_COOKIE, $COKKIES . " expires=Mon, 14-Apr-08 10:34:13 GMT"); } // если с сервера пришло cookie, то запишем его в файл $cookie_file //@curl_setopt ( $ch , CURLOPT_COOKIEJAR , $cookie_file ); //@curl_setopt ( $ch , CURLOPT_COOKIEFILE , $cookie_file ); // если мы послали данные из формы, которая стоит // на страничке $path, добавляем метод $_POST if (isset($_POST) and $_SERVER["REQUEST_METHOD"] == "POST") { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, substr(data_encode($_POST), 0, -1)); } // получаем страничку $path с хедером $tmp = curl_exec($ch); // закрываем сеанс Curl curl_close($ch); // если Curl ничего не вывел пробуем это сделать output_r(); // эта функция описана здесь, она использует сокет. if ($tmp == '') { $tmp = output_r($path); } //print $tmp; return $tmp; }
function data_encode($data, $keyprefix = "", $keypostfix = "") { assert(is_array($data)); $vars = null; foreach ($data as $key => $value) { if (is_array($value)) { $vars .= data_encode($value, $keyprefix . $key . $keypostfix . urlencode("["), urlencode("]")); } else { $vars .= $keyprefix . $key . $keypostfix . "=" . urlencode($value) . "&"; } } return $vars; }
if (!isset($frequencies[$chapter])) { unset($wordcount[$chapter]); } } // Unset any frequency data which doesn't have matching wordcount data foreach ($frequencies as $chapter => $data) { if (!isset($wordcount[$chapter])) { unset($frequencies[$chapter]); } } $chapters = array(); // Merge the frequency and wordcount data foreach ($wordcount as $chapter => $data) { $chapters[$chapter] = array('unique_words' => $frequencies[$chapter]['total'], 'total_words' => $wordcount[$chapter]['words'], 'total_headers' => $wordcount[$chapter]['headers'], 'total_floats' => $wordcount[$chapter]['floats'], 'common_words' => $frequencies[$chapter]['words']); } function data_encode($data) { return urlencode(gzcompress(serialize($data))); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, THESIS_WEB_POST_URL); // URL to submit data to curl_setopt($curl, CURLOPT_POST, true); // POST the data curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return the result rather than spitting it out curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); // Remove the expect header since Lighttpd goes ape shit curl_setopt($curl, CURLOPT_POSTFIELDS, array('userid' => data_encode(THESIS_WEB_USERID), 'secret' => data_encode(THESIS_WEB_SECRET), 'date' => data_encode($now), 'pages' => data_encode($numpages), 'references' => data_encode($references), 'chapters' => data_encode($chapters), 'status' => data_encode($status))); echo curl_exec($curl) . "\n"; exit(curl_errno($curl));