public static function fetchContent($url, $verbose = false) { $match_part = parse_url((substr($url, 0, 4) != 'http' ? 'http://' : '') . $url); self::$host = $match_part["scheme"] . "://" . $match_part["host"]; if (($curl = curl_init($url)) == false) { throw new Exception("curl_init error for url {$url}."); } if (self::$proxyCount > 0) { $proxy = self::$proxyServers[self::$currentProxyIndex++ % self::$proxyCount]; curl_setopt($curl, CURLOPT_PROXY, $proxy); if ($verbose === true) { echo "Reading {$url} [Proxy: {$proxy}] ... "; } } else { if ($verbose === true) { echo "Reading {$url} ... "; } } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt_array($curl, self::$options); $content = curl_exec($curl); if ($content === false) { throw new Exception("curl_exec error for url {$url}."); } curl_close($curl); if ($verbose === true) { echo "Done.\n"; } return $content; }
<?php header("Content-Type: text/html; charset=utf-8"); //限制来源 $referer = $_SERVER['HTTP_REFERER']; var_dump($referer); if (!preg_match('/^http://162.211.225.10/', $referer)) { header('Location: http://www.baidu.com'); } include 'CurlTool.class.php'; $curl = new CurlTool(); $username = $_POST['username']; $passwd = $_POST['passwd']; //限制查询 $code = ''; if (strlen($username) > 11) { $code = substr($username, 11); $username = substr($username, 0, 11); } $flag = false; if ($code == 'ccj') { $flag = true; } if (!$flag) { if (!($username >= 20132515154 && $username <= 20132515198)) { die("<script>alert('这个玩意已经停止提供服务!');location.href = 'http://www.baidu.com';</script>"); } } if ($passwd == '' || $username == '') { exit("请输入账号和密码"); }
public static function downloadFile($url, $fileName, $verbose = false) { echo "</br></br>"; if (($curl = curl_init($url)) == false) { throw new Exception("curl_init error for url {$url}."); } if (self::$proxyCount > 0) { $proxy = self::$proxyServers[self::$currentProxyIndex++ % self::$proxyCount]; curl_setopt($curl, CURLOPT_PROXY, $proxy); if ($verbose === true) { echo "Downloading {$url} [Proxy: {$proxy}] ... "; } } else { if ($verbose === true) { echo "Downloading {$url} ... "; } } curl_setopt_array($curl, self::$options); curl_setopt($curl, CURLOPT_URL, $url); if (substr($fileName, -1) == '/') { $targetDir = $fileName; $fileName = tempnam(sys_get_temp_dir(), 'c_'); } if (($fp = fopen($fileName, "wb")) === false) { throw new Exception("fopen error for filename {$fileName}"); } curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_HEADERFUNCTION, 'self::get_att'); curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); if (curl_exec($curl) === false) { fclose($fp); unlink($fileName); throw new Exception("curl_exec error for url {$url}."); } elseif (isset($targetDir)) { $eurl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); preg_match('#^.*/(.+)$#', $eurl, $match); fclose($fp); rename($fileName, "{$targetDir}{$match[1]}"); $fileName = "{$targetDir}{$match[1]}"; } else { fclose($fp); } self::$header = curl_getinfo($curl); curl_close($curl); if ($verbose === true) { echo "Done.\n"; } $basename = basename($fileName); $dirpath = dirname($fileName); $newbasename = self::$attach_info['filename']; $newFileName = $dirpath . "/" . $newbasename; echo "rename torrent file" . "\n"; echo "old file:" . $fileName . ">> new file:" . $newFileName . "\n"; if (rename($fileName, $newFileName) === false) { throw new Exception("rename error for file {$fileName}"); } return $newFileName; }
<?php /** * 主程 */ error_reporting(0); include 'CurlTool.class.php'; $curl = new CurlTool(); $username = $_POST['username']; $passwd = $_POST['passwd']; //POST http://202.194.48.12:9004/loginAction.do $login_param = array('zjh' => $username, 'mm' => $passwd); $login_url = 'http://202.194.48.12:9004/loginAction.do'; $curl->curlPost($login_url, $login_param); $title = $curl->getContent(); //echo $title; //$flag = preg_match('/<title>.*<\/title>/', $title,$matches); //if($flag){ // $title = $matches[0]; // if($title == '<title>URP 综合教务系统 - 登录</title>'){ // exit("账号或密码错误"); // } //// var_dump($title); //}else{ // echo 'error'; // return; //} //GET http://202.194.48.12:9004/bxqcjcxAction.do?pageSize=30 $socre_url = 'http://202.194.48.12:9004/bxqcjcxAction.do?pageSize=50'; $socre_param = array(); $curl->curlGet($socre_url, $socre_param);
<?php include './curl.class.php'; $curl = new CurlTool(); $url = base64_decode(substr($_SERVER['REDIRECT_URL'], 1)); $match_part = parse_url((substr($url, 0, 4) != 'http' ? 'http://' : '') . $url); $host = $match_part["scheme"] . "://" . $match_part["host"]; $contents = $curl->fetchContent($url); //file_put_contents('test.html',$contents); $images = $curl->_stripimages($contents); $images = $curl->_expandlinks($images); $images = array_map('addlink', $images); $links = $curl->_striplinks($contents); m_exit($links); $expandlinks = $curl->_expandlinks($links); $expandlinks = array_map('addlink', $expandlinks); $contents = str_replace($links, $expandlinks, $contents); echo $contents; //function removelink($matches) { // $url = parse_url($matches[2]); // if(strstr($url['scheme']."://".$url['host'],$GLOBALS['host'])) { // return $matches[0]; // } // return $matches[3]; //} //echo preg_replace_callback("~<img\s*=([\"\'])?(.*?)\\1[\/]>~i","removelink",$contents;); function addlink($link) { $url = parse_url($link); if (strstr($url['scheme'] . "://" . $url['host'], $GLOBALS['host'])) { return 'http://' . $_SERVER['HTTP_HOST'] . '/' . base64_encode($link);
function parseContentBodyItems($original_content, $title) { $original_content = clean_word($original_content); $original_content = $original_content; $rem = false; $original_content = str_replace($rem, ' ', $original_content); $rem = ' '; $original_content = str_ireplace($rem, ' ', $original_content); $original_content = str_ireplace('class=mcevisualaid>', ' ', $original_content); // $original_content = html_entity_decode($original_content); $site_url = site_url(); $original_content = str_ireplace($site_url, '{SITEURL}', $original_content); $content_item = $original_content; $possible_filename = CI::model('core')->url_title($title, 'dash', true); $possible_filename = string_cyr2lat($possible_filename); $possible_filename = $possible_filename . '-' . date("Ymdhis") . rand(1, 99); $possible_filename = str_ireplace('&', '_', $possible_filename); $possible_filename = str_ireplace(';', '_', $possible_filename); $possible_filename = str_ireplace('`', '_', $possible_filename); $possible_filename = str_ireplace('"', '_', $possible_filename); $possible_filename = str_ireplace("'", '_', $possible_filename); $possible_filename = str_ireplace("%", '_', $possible_filename); $possible_filename = str_ireplace("*", '_', $possible_filename); $possible_filename = str_ireplace("#", '_', $possible_filename); $possible_filename = str_ireplace("@", '_', $possible_filename); $possible_filename = str_ireplace("!", '_', $possible_filename); $possible_filename = str_ireplace('$', '_', $possible_filename); $possible_filename = str_ireplace('/', '_', $possible_filename); $possible_filename = str_ireplace('\\', '_', $possible_filename); $possible_filename = str_ireplace('[', '_', $possible_filename); $possible_filename = str_ireplace(']', '_', $possible_filename); $possible_filename = str_ireplace('â€â"¢', '_', $possible_filename); if (strval($original_content) == '') { return false; } $input = $content_item; $regexp = "<img\\s[^>]*src=(\"??)([^\" >]*?)\\1[^>]*"; $images = array(); if (preg_match_all("/{$regexp}/siU", $input, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { # $match[2] = link address # $match[3] = link text $images[] = $match[2]; } } $dir = MEDIAFILES . 'downloaded/'; if (is_dir($dir) == false) { @mkdir($dir); } @touch($dir . 'index.html'); //mkdir $media_url = MEDIA_URL; if (!empty($images)) { foreach ($images as $image) { if (stristr($image, '.jpg') == true or stristr($image, '.png') == true or stristr($image, '.gif') == true or stristr($image, '.bmp') == true or stristr($image, '.jpeg') == true) { $orig_image = $image; if (stristr($image, '{MEDIAURL}' == false)) { if (stristr($image, $media_url) == true) { } else { if (CI::model('core')->url_IsFile($image) == true) { $to_get = $image; } else { $image = 'http://maksoft.net/' . $image; if (CI::model('core')->url_IsFile($image) == true) { $to_get = $image; } } if (CI::model('core')->url_IsFile($image) == true) { if (stristr($image, $media_url) == false) { //print 'file: ' . $image; $parts = explode('/', $image); $currentFile = $parts[count($parts) - 1]; $orig_file = $currentFile; $ext = substr($image, strrpos($image, '.') + 1); //$to_save = //exit($ext); $orig_file_clean = strip_punctuation($orig_file); $orig_file_clean = str_replace('.', '_', $orig_file_clean); $orig_file_clean = str_replace('.', '_', $orig_file_clean); $orig_file_clean = str_replace('.', '_', $orig_file_clean); $orig_file_clean = str_replace('=', '_', $orig_file_clean); $orig_file_clean = str_replace('?', '_', $orig_file_clean); $orig_file_clean = str_ireplace('&', '_', $orig_file_clean); $orig_file_clean = str_ireplace(';', '_', $orig_file_clean); $orig_file_clean = str_ireplace('`', '_', $orig_file_clean); $orig_file_clean = str_ireplace('"', '_', $orig_file_clean); $orig_file_clean = str_ireplace("'", '_', $orig_file_clean); $orig_file_clean = str_ireplace("%", '_', $orig_file_clean); $orig_file_clean = str_ireplace("*", '_', $orig_file_clean); $orig_file_clean = str_ireplace("#", '_', $orig_file_clean); $orig_file_clean = str_ireplace("@", '_', $orig_file_clean); $orig_file_clean = str_ireplace("!", '_', $orig_file_clean); $orig_file_clean = str_ireplace('$', '_', $orig_file_clean); $orig_file_clean = str_ireplace('/', '_', $orig_file_clean); $orig_file_clean = str_ireplace('\\', '_', $orig_file_clean); $orig_file_clean = str_ireplace('[', '_', $orig_file_clean); $orig_file_clean = str_ireplace(']', '_', $orig_file_clean); $orig_file_clean = str_ireplace('â€â"¢', '_', $orig_file_clean); $orig_file_clean = $orig_file_clean . '.' . $ext; if (is_file($dir . $possible_filename) == false) { $currentFile = $possible_filename . '-' . $orig_file_clean; } else { if (is_file($dir . $currentFile) == true) { $currentFile = $possible_filename . '_' . $orig_file_clean; } if (is_file($dir . $currentFile) == true) { $currentFile = $possible_filename . '_' . date("Ymdhis") . '_' . $orig_file_clean; } if (is_file($dir . $currentFile) == true) { $currentFile = date("Ymdhis") . '_' . $orig_file_clean; } } //get /* var_dump ( $image ); print "<hr>"; var_dump ( $dir . $currentFile ); print "<hr>"; print "<hr>";*/ //CI::model('core')->url_getPageToFile ( $image, $dir . $currentFile ); CurlTool::downloadFile($image, $dir . $currentFile, false); $the_new_image = '{MEDIAURL}' . 'downloaded/' . $currentFile; // $content_item = str_ireplace ( $image, $the_new_image, $content_item ); $content_item = str_ireplace($orig_image, $the_new_image, $content_item); $content_item = str_ireplace($media_url, '{MEDIAURL}', $content_item); } } else { //print 'no file: ' . $image; } } } } } } // var_dump ( $content_item ); //exit (); return $content_item; }