function get_image() { $id = rand(101, 585295); //id изображений на сайте начинаются со 101. 585295 далеко не последнее изображение, так что можно смело писать цифру побольше $url = "http://nuclear-wallpapers.ru.com/download.php?id=" . $id . "&width=1366&height=768"; /* $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); $res = curl_exec($ch); curl_close($ch); */ $img = "http://white-wallpapers.ru/image/" . $id . "-1366-768-nuclear-wallpapers.ru.com.jpg"; /* *Эту проверку делал для себя, на случай отсутствия интернета.. */ $check = get_headers($url); if ($check[0] !== 'HTTP/1.1 200 OK') { //проверяем, нормальный ли заголовок нам возвращается $dir = opendir('/mnt/trash/dl/wllpprs/'); while (false !== ($file = readdir($dir))) { $images[] = $file; } shuffle($images); $img = '/mnt/trash/dl/wllpprs/' . $images[0]; copy($img, '/home/nikolay/walls/wall.jpg'); } else { if (!getimagesize($img)) { //бывает, что попадается битое изображение, так что проверяется его размер get_image(); } else { copy('/home/nikolay/walls/wall.jpg', '/home/nikolay/walls/old_wall.jpg'); copy($img, '/home/nikolay/walls/wall.jpg'); } } }
public function render() { $headers = array(); $response = ''; if (count($this->route_matches) > 1) { $site = $this->route_matches[1]; if (!preg_match('@^https?://@i', $site)) { $site = 'http://' . $site; } $headers = @get_headers($site); if (!$headers) { error400('Headers could not be retrieved for that domain.'); return; } foreach ($headers as $header) { $response .= htmlspecialchars($header . "\n"); } } else { $headers = getallheaders(); foreach ($headers as $key => $value) { if (server_or_default('HTTP_X_DAGD_PROXY') == "1") { if (strpos($key, 'X-Forwarded-') === 0 || $key == 'X-DaGd-Proxy') { continue; } } $response .= htmlspecialchars($key . ': ' . $value . "\n"); } } return $response; }
function lrss_is_site_available($url) { //check, if a valid url is provided if (!filter_var($url, FILTER_VALIDATE_URL)) { return FALSE; } if (!function_exists('curl_init') && function_exists('get_headers')) { $headers = get_headers($url, 1); if ($headers[0] == 'HTTP/1.1 200 OK') { return TRUE; } else { return FALSE; } } else { if (function_exists('curl_init') && !function_exists('get_headers')) { return FALSE; } } $handle = curl_init(urldecode($url)); curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 0.5); curl_setopt($handle, CURLOPT_TIMEOUT, 1); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($handle); $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); if ($httpCode >= 200 && $httpCode < 400) { return TRUE; } else { return FALSE; } curl_close($handle); }
function FileSizeOf($link) { if (strpos($link, get_option('siteurl')) === false) { $link = str_replace(' ', '%20', $link); if (function_exists('get_headers')) { $headers = @get_headers($link, 1); if ($headers['Content-Length'] == '') { return; } $size = $headers['Content-Length']; } else { $file = @file_get_contents($link); if ($file == false) { return; } $size = strlen($file); } } else { $file = ABSPATH . 'wp-content/plugins/downloads-manager/upload/' . basename($link); $size = @filesize($file); } $i = 0; $type = array("B", "KB", "MB", "GB"); while ($size / 1024 > 1) { $size = $size / 1024; $i++; } return substr($size, 0, strpos($size, '.') + 3) . $type[$i]; }
/** * Follows redirects of a url and returns the final one. * * @param string $url * @param int $timeout * @return mixed */ function get_final_url($url, $timeout = 120) { $url = str_replace("&", "&", urldecode(trim($url))); $cookie = tempnam("/tmp", "CURLCOOKIE"); $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); $content = curl_exec($ch); $response = curl_getinfo($ch); curl_close($ch); if ($response['http_code'] == 301 || $response['http_code'] == 302) { ini_set("user_agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"); $headers = get_headers($response['url']); $location = ""; foreach ($headers as $value) { if (substr(strtolower($value), 0, 9) == "location:") { return get_final_url(trim(substr($value, 9, strlen($value)))); } } } if (preg_match("/window\\.location\\.replace\\('(.*)'\\)/i", $content, $value) || preg_match("/window\\.location\\=\"(.*)\"/i", $content, $value)) { return get_final_url($value[1]); } else { return $response['url']; } }
public function exists($email) { $this->setDefaultImage('404'); $url = $this->buildGravatarURL($email); $headers = get_headers($url, 1); return strpos($headers[0], '200') ? true : false; }
/** * @depends testGetAvailableLanguages */ public function testGetPoFileUrl() { $url = ZurmoTranslationServerUtil::getPoFileUrl('de'); $headers = get_headers($url); list($version, $status_code, $msg) = explode(' ', $headers[0], 3); $this->assertEquals(200, intval($status_code)); }
function check_uri($uri) { global $coinTypes; //if the URI is in the array if (array_key_exists($uri, $coinTypes)) { if ($coinTypes[$uri] == true) { echo "Found {$uri}\n"; $valid = true; } else { echo "Did not find {$uri}\n"; $valid = false; } } else { $file_headers = @get_headers($uri); if ($file_headers[0] == 'HTTP/1.1 200 OK') { echo "Matched new {$uri}\n"; $coinTypes[$uri] = true; $valid = true; } else { echo "Did not find {$uri}\n"; $coinTypes[$uri] = false; $valid = false; } } return $valid; }
function wp_lightbox_is_valid_url($url) { $url = @parse_url($url); if (!$url) { return false; } $url = array_map('trim', $url); $url['port'] = !isset($url['port']) ? 80 : (int) $url['port']; $path = isset($url['path']) ? $url['path'] : ''; if ($path == '') { $path = '/'; } $path .= isset($url['query']) ? "?{$url['query']}" : ''; if (isset($url['host']) and $url['host'] != gethostbyname($url['host'])) { if (PHP_VERSION >= 5) { $headers = get_headers("{$url['scheme']}://{$url['host']}:{$url['port']}{$path}"); } else { $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30); if (!$fp) { return false; } fputs($fp, "HEAD {$path} HTTP/1.1\r\nHost: {$url['host']}\r\n\r\n"); $headers = fread($fp, 128); fclose($fp); } $headers = is_array($headers) ? implode("\n", $headers) : $headers; return (bool) preg_match('#^HTTP/.*\\s+[(200|301|302)]+\\s#i', $headers); } return false; }
public function check_if_requires_auth() { global $C; $result = FALSE; if ($this->has_curl) { $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_AUTOREFERER => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5, CURLOPT_MAXREDIRS => 3, CURLOPT_REFERER => $C->SITE_URL, CURLOPT_URL => $this->url)); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); if (!empty($this->userpwd)) { curl_setopt($ch, CURLOPT_USERPWD, $this->userpwd); } $result = curl_exec($ch); $result = trim($result); curl_close($ch); } elseif (function_exists('get_headers')) { $result = get_headers($this->url); $result = $result ? implode("\n", $result) : FALSE; } if (!$result || empty($result)) { return FALSE; } if (preg_match('/(^|\\n|\\r)(\\s)*HTTP\\/[0-9.]+(\\s)+401(\\s)+Authorization(\\s)+Required(\\s)*($|\\n|\\r)/is', $result)) { if (preg_match('/(^|\\n|\\r)(\\s)*WWW\\-Authenticate\\:\\s([a-z0-9-]+)/i', $result)) { return TRUE; } } if (preg_match('/(^|\\n|\\r)(\\s)*HTTP\\/[0-9.]+(\\s)+401(\\s)+Unauthorized(\\s)*($|\\n|\\r)/is', $result)) { if (preg_match('/(^|\\n|\\r)(\\s)*WWW\\-Authenticate\\:\\s([a-z0-9-]+)/i', $result)) { return TRUE; } $this->error = TRUE; return FALSE; } return FALSE; }
function retrieve_remote_file_size($url) { if (function_exists('curl_version')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); $data = curl_exec($ch); $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); curl_close($ch); return $size; } elseif (function_exists('get_headers')) { $remote_header = get_headers($file_url, true); if ($remote_header !== false) { $remote_header = array_change_key_case($remote_header); if (!empty($remote_header['content-length'])) { $filesize = (double) $remote_header['content-length']; } } return isset($filesize) ? $filesize : false; } else { return false; } }
/** * Execute command * * @param InputInterface $input Input * @param OutputInterface $output Output * * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::setup($input, $output); $id = $input->getArgument('id'); $user = $this->u->getArrayInfosFromUtilisateur($id); $pageName = 'Utilisateur:' . $user['prenom'] . ' ' . $user['nom']; $output->writeln('<info>Exporting "' . $pageName . '"…</info>'); $content = ''; $this->loginAsAdmin(); $this->deletePage($pageName); //Login as user $this->login($user['prenom'] . ' ' . $user['nom']); $oldPath = 'http://www.archi-wiki.org/images/avatar/' . $id . '/original.jpg'; $headers = get_headers($oldPath, 1); if ($headers[0] == 'HTTP/1.1 200 OK') { $filename = 'Avatar ' . $user['prenom'] . ' ' . $user['nom'] . '.jpg'; $params = array('filename' => $filename, 'token' => $this->api->getToken('edit'), 'url' => $oldPath); if ($input->getOption('force')) { $params['ignorewarnings'] = true; } $output->writeln('<info>Exporting "File:' . $filename . '"…</info>'); $this->api->postRequest(new Api\SimpleRequest('upload', $params, array())); } else { $filename = ''; } $this->savePage($pageName, '{{Infobox utilisateur |site=' . $user['urlSiteWeb'] . ' |avatar=' . $filename . ' }}', "Profil importé depuis Archi-Wiki"); }
/** * Загрузка: */ public function upload($url) { $kvs = KVS::getInstance(); if ($kvs->exists(__CLASS__, $url)) { return $kvs->get(__CLASS__, $url); } $data = @get_headers($url, 1); if (in_array($data['Content-Type'], array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'))) { $tm = tempnam('/tmp', 'img'); $nam = md5(uniqid('', true)); $dir = substr($nam, 0, 1); $im = fopen($url, 'r'); $fp = fopen($tm, 'w'); $start = time(); while (!feof($im) && time() - $start < 5) { fputs($fp, fgets($im, 24)); } fclose($im); fclose($fp); if (time() - $start > 5) { return false; } self::createThumbnail($tm, UPLOAD_PATH . '/news/' . $dir . '/' . $nam . '.png'); $p = '/uploads/news/' . $dir . '/' . $nam . '.png'; @unlink(tm); $kvs->set(__CLASS__, $url, null, '/uploads/news/' . $dir . '/' . $nam . '.png'); $kvs->expire(__CLASS__, $url, null, 60 * 60 * 24 * 30); return $p; } return false; }
public function downloadLangInstaller($resources, $language) { // check tmp if ($warning = $this->app->zlfw->path->checkSystemPaths()) { $response['success'] = false; $response['errors'][] = $warning; echo json_encode($response); jexit(); } $this->_initCheck(); // set default file name $filename = $language . '.' . (count($resources) > 1 ? 'language_pack' : $resources[0]) . '.zip'; // set url $url = self::$apiUrl . 'getLangInstaller&resources=' . implode(',', $resources) . '&language=' . $language; // attempt to override file name with one from header response $headers = get_headers($url, 1); if (isset($headers['Content-Disposition'])) { if (preg_match('/name="(?P<filename>.+?)"/', $headers['Content-Disposition'], $matches)) { $filename = $matches['filename']; } } // set file destination $file = JPath::clean(JPATH_SITE . '/tmp/' . $filename); // download $result = $this->app->zl->extensions->download($url, $file); return $file; }
function get_remote_menu($menu_name) { global $wp_customize; $customizing = isset($wp_customize); $result_name = $menu_name . '_json'; $result = get_transient($result_name); if (false === $result || $customizing) { $opts = array('http' => array('timeout' => 15)); $context = stream_context_create($opts); $file_location = get_theme_mod_or_default($menu_name . '_feed'); if (empty($file_location)) { return; } $headers = get_headers($file_location); $response_code = substr($headers[0], 9, 3); if ($response_code !== '200') { return; } $result = json_decode(file_get_contents($file_location, false, $context)); if (!$customizing) { set_transient($result_name, $result, 60 * 60 * 24); } } return $result; }
function add_uw_feed_enclosure_image() { global $post; $thumbnailID = get_post_thumbnail_id($post->ID); if (!empty($thumbnailID)) { $url = wp_get_attachment_image_src($thumbnailID, 'rss'); $url = $url[0]; //$mime = get_post_mime_type($thumbnailID); unneeded DB call to get mime type $img_headers = get_headers($url); foreach ($img_headers as $img_header) { $info = explode(" ", $img_header); if ($info[0] == 'Content-Length:') { $size = $info[1]; } else { if ($info[0] == 'Content-Type:') { $mime = $info[1]; } } } ?> <enclosure url="<?php echo $url; ?> " type="<?php echo $mime; ?> " size="<?php echo $size; ?> " /> <?php } }
function get_data($start) { if ($_GET['q'] != '') { $url = 'https://www.googleapis.com/customsearch/v1element?prettyPrint=false&key=' . $this->key . '&cx=' . $this->cx . '&q=' . rawurlencode($_GET['q']) . '&start=' . $start; //$url2='https://www.googleapis.com/customsearch/v1?key='.$this->key.'&cx='.$this->cx.'&q='.rawurlencode($_GET['q']).'&start='.$start; $result = json_decode(@file_get_contents($url), true); foreach ($result['results'] as $data) { $c++; $result2[$c]['url'] = $data['formattedUrl']; $result2[$c]['des'] = $data['content']; $result2[$c]['title'] = $data['title']; $result2[$c]['link'] = $data['url']; $image_header = @get_headers($data['richSnippet']['cseThumbnail']['src']); if (strpos($headers[0], '404') === false) { $result2[$c]['image'] = $data['richSnippet']['cseThumbnail']['src']; //$data['richSnippet']['cseImage']['src']; } } /*foreach ($result['items'] as $data) { $c++; $result2[$c]['url']=$data['htmlFormattedUrl']; $result2[$c]['des']=$data['htmlSnippet']; $result2[$c]['link']=$data['link']; $image_header = @get_headers($data['pagemap']['cse_thumbnail'][0]['src']); if(strpos($headers[0],'404') === false) { $result2[$c]['image']=$data['pagemap']['cse_thumbnail'][0]['src']; //$data['pagemap']['cse_image'][0]['src']; } $result2[$c]['title']=$data['htmlTitle']; }*/ return $result2; } }
public function install() { $e = get_headers(ERP_WS); if ($e[0] == 'HTTP/1.1 200 OK') { if ($this->isCurlInstalled() == false) { $this->_errors[] = $this->l('Error while installing the module. CURL Extension is not active on your server. Please contact your server administrator.'); return false; } if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!Configuration::hasKey('ERP_ADMIN_PARENT_ORDERS_TAB_ID')) { Configuration::updateValue('ERP_ADMIN_PARENT_ORDERS_TAB_ID', Tab::getIdFromClassName('AdminParentOrders')); } if (parent::install() != false && $this->parseSQL('install.sql') != false && $this->installStockMvtReason() != false && $this->installErpTab() != false && $this->addTrashCategory() != false && $this->addOrderState($this->l('Order to the supplier')) != false && $this->registerHook('actionOrderStatusUpdate') != false && $this->registerHook('displayBackOfficeHeader') != false) { foreach ($this->field_name_configuration as $field_name => $param) { Configuration::updateValue(Tools::strtoupper($field_name), $param['default']); } // load a licence if exits $this->loadLicenceIfExists(); // save the first install date if (!Configuration::hasKey('ERP_FIRST_INSTALL_DATE') || Configuration::get('ERP_FIRST_INSTALL_DATE') == '' || Configuration::get('ERP_FIRST_INSTALL_DATE') == false) { Configuration::updateValue('ERP_FIRST_INSTALL_DATE', date("Y-m-d H:i:s")); } return true; } return false; } else { $this->_errors[] = $this->l('Error while getting headers of WS ! Please contact the customer service.'); return false; } }
/** ** Function: validate_full_url() ** Return: string containing validation error ** -OR- FALSE if valid URL provided. ** ** This function should be called to validate the user's input for ** a full URL (that will eventually be shortened). **/ function validate_full_url() { // Form for shortening URL submitted. Validate input. if (empty(trim($_POST['full_url']))) { // No input provided. Create error message and display the form again. $error['full_url'] = "URL field is required."; return $error; } // If the user did not include display an error in the form. if (stripos($_POST['full_url'], "http://") === FALSE) { $error['full_url'] = "URLs must include 'http://' at the beginnning."; return $error; } $headers = get_headers($_POST['full_url'], 1); if ($headers === FALSE) { // Invalid URL or failure acessing the URL. Create error and display form again. $error['full_url'] = "Invalid URL was provided."; return $error; } // $response array will include redirects and lots of extra info. // This will look nasty, if there is time I can clean this up. $rheaders = array_reverse($headers, TRUE); foreach ($rheaders as $key => $value) { // Find the first key that is numeric if (is_numeric($key)) { $response = substr($value, 9, 3); if (strcmp($response, "200") === FALSE) { $error['full_url'] = "Invalid URL was provided."; return $error; } } } // URL seems to be valid. return FALSE; }
/** * Make a search from the Google Image API, * Browse the results, * Exclude "not found", "forbidden", "unavailable" status, * Return the path of the found image. * If not found, return an empty string. * If $thumb = true return the thumbnail image width, ortherwise return the full image width. * @param string $search * @param bool $thumb */ function getGoogleImg($search, $thumb = false) { // Clean search string to remove special chars, and replace spaces with + $clean_str = cleanString($search, array(), '+'); // If $thumb = true, look for the thumbnail url, otherwise look for the full image url $target = $thumb ? 'tbUrl' : 'url'; // Construct the Google Image API query $query = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=' . urlencode($clean_str); // Get the result from query, returns a JSON object $json = file_get_contents($query); // Converts the JSON object in PHP array $results = json_decode($json, true); // If there are results from the query if (!empty($results["responseData"]["results"])) { // Browse each result from response and set it in $result foreach ($results["responseData"]["results"] as $result) { // Retrieve the HTTP headers $file_headers = @get_headers($result[$target]); // If HTTP headers don't contain status 403 (forbidden), 404 (not found) or 503 (unavailable) if (strpos($file_headers[0], '403') === false && strpos($file_headers[0], '404') === false && strpos($file_headers[0], '503') === false) { // Return the absolute image path (http://...) from result with $target as key return $result[$target]; } } } // No image found, return an empty string return ''; }
public function executeCheckLaunchPage($launchPage) { if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, true); //curl_setopt($ch, CURLOPT_NOBODY, true); //Sometimes this doesn't work curl_setopt($ch, CURLOPT_URL, $launchPage); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $output = curl_exec($ch); $headersSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close($ch); if ($output !== false) { $headers = substr($output, 0, $headersSize); $headersLines = explode("\n", $headers); } } else { $headersLines = get_headers($launchPage); $output = $headersLines; } $isLaunchable = true; if ($output === false) { $isLaunchable = false; } else { foreach ($headersLines as $header) { $parts = explode(':', $header, 2); if (count($parts) == 2 && preg_match('#x-frame-options#i', trim($parts[0])) && preg_match('#"?(sameorigin|deny)"?#i', trim($parts[1]))) { $isLaunchable = false; break; } } } return array('isLaunchable' => $isLaunchable, 'headers' => $headersLines); }
/** * If a YouTube or Vimeo video is added in the post content, grab its thumbnail and set it as the featured image */ function wds_set_media_as_featured_image($post_id, $post) { $content = isset($post->post_content) ? $post->post_content : ''; // Only check the first 1000 characters of our post. $content = substr($content, 0, 800); // Props to @rzen for lending his massive brain smarts to help with the regex $do_video_thumbnail = isset($post->ID) && !has_post_thumbnail($post_id) && $content && (preg_match('/\\/\\/(www\\.)?youtube\\.com\\/(watch|embed)\\/?(\\?v=)?([a-zA-Z0-9\\-\\_]+)/', $content, $youtube_matches) || preg_match('#https?://(.+\\.)?vimeo\\.com/.*#i', $content, $vimeo_matches)); if (!$do_video_thumbnail) { return update_post_meta($post_id, '_is_video', false); } $video_thumbnail_url = false; $youtube_id = $youtube_matches[4]; $vimeo_id = preg_replace("/[^0-9]/", "", $vimeo_matches[0]); if ($youtube_id) { // Check to see if our max-res image exists $file_headers = get_headers('http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg'); $video_thumbnail_url = $file_headers[0] !== 'HTTP/1.0 404 Not Found' ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg'; } elseif ($vimeo_id) { $vimeo_data = wp_remote_get('http://www.vimeo.com/api/v2/video/' . intval($vimeo_id) . '.php'); if (isset($vimeo_data['response']['code']) && '200' == $vimeo_data['response']['code']) { $response = unserialize($vimeo_data['body']); $video_thumbnail_url = isset($response[0]['thumbnail_large']) ? $response[0]['thumbnail_large'] : false; } } // If we found an image... $attachment_id = $video_thumbnail_url && !is_wp_error($video_thumbnail_url) ? wds_ms_media_sideload_image_with_new_filename($video_thumbnail_url, $post_id, sanitize_title(get_the_title())) : 0; // If attachment wasn't created, bail if (!$attachment_id) { return; } // Woot! we got an image, so set it as the post thumbnail set_post_thumbnail($post_id, $attachment_id); update_post_meta($post_id, '_is_video', true); }
function choose_torrent_link($links) { $link_best = ""; $word_matches = 0; if (count($links) == 0) { return ""; } //Check how many links has ".torrent" in them foreach ($links as $link) { if (preg_match("/\\.torrent/", $link)) { $link_best = $link; $word_matches++; } } //If only one had ".torrent", use that, else check http content-type for each, //and use the first that returns the proper torrent type if ($word_matches != 1) { foreach ($links as $link) { $opts = array('http' => array('timeout' => 10)); stream_context_get_default($opts); $headers = get_headers($link, 1); if (isset($headers['Content-Disposition']) && preg_match('/filename=.+\\.torrent/i', $headers['Content-Disposition']) || isset($headers['Content-Type']) && $headers['Content-Type'] == 'application/x-bittorrent') { $link_best = $link; break; } } } //If still no match has been made, just select the first, and hope the html torrent parser can find it if (empty($link_best)) { $link_best = $links[0]; } return $link_best; }
public function process() { $http_host = $_SERVER['HTTP_HOST']; if ($http_host == 'localhost:8080') { $http_host = 'localhost'; } $host_name = 'http://' . $http_host; $actual_url = str_replace($host_name, '', APPLICATION_ROOT); $actual_url = str_replace($actual_url, '', $_SERVER['REQUEST_URI']); $size = $this->getP3(); if (!$size) { location('/error/base/' . urlencode('The url was invalid')); } $size_ex = explode('x', $size); $height = isset($size_ex[0]) ? $size_ex[0] : '100'; $width = isset($size_ex[1]) ? $size_ex[1] : '100'; $image_path = str_replace('/images/process/' . $size, '', $actual_url); $full_image_path = 'http://' . $http_host . $image_path; $headers = get_headers($full_image_path); foreach ($headers as $header) { if (strpos($header, 'Content-Type') !== false) { header($header); } } $new_url = 'http://' . $http_host . href('/framework/external/timthumb/timthumb.php'); $new_url .= '?src=' . $image_path; $new_url .= '&h=' . $height; $new_url .= '&w=' . $width; echo file_get_contents($new_url); }
function server_http_headers($host, $ip, $port) { global $timeout; // first check if server is http. otherwise long timeout. $ch = curl_init("https://" . $ip . ":" . $port); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: {$host}")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); if (curl_exec($ch) === false) { curl_close($ch); return false; } curl_close($ch); stream_context_set_default(array("ssl" => array("verify_peer" => false, "capture_session_meta" => true, "verify_peer_name" => false, "peer_name" => $host, "allow_self_signed" => true, "sni_enabled" => true), 'http' => array('method' => 'GET', 'max_redirects' => 1, 'header' => 'Host: ' . $host, 'timeout' => $timeout))); $headers = get_headers("https://{$ip}:{$port}", 1); if (!empty($headers)) { $headers = array_change_key_case($headers, CASE_LOWER); return $headers; } }
function url_exist($url) { $h = get_headers($url); $status = array(); preg_match('/HTTP\\/.* ([0-9]+) .*/', $h[0], $status); return $status[1] == 200; }
public function convert() { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->initURL); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.jar'); curl_setopt($ch, CURLOPT_REFERER, "http://www.youtube-mp3.org/"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); $content = curl_exec($ch); curl_close($ch); $pm = preg_match("/Location: (.*?)/iU", $content, $matches); $r = rtrim($matches[1]); $result = isset($r) ? array("status" => true, "url" => $r) : array("status" => false); if ($result["status"]) { $headers = get_headers($result["url"], 1); $fn = explode("?", basename($result["url"])); $this->fileName = $fn[0]; $this->fileInfo = array("id" => $this->videoID, "name" => $this->fileName, "size" => $headers["Content-Length"], "url" => $result["url"], "headers" => array("Content-Type: {$headers["Content-Type"]}", "Content-Length: {$headers["Content-Length"]}", "Content-Transfer-Encoding: Binary", "Content-disposition: attachment; filename={$this->fileName}")); } else { $this->fileInfo = false; } return $this; }
public function login($email, $pass, $options = array()) { // Import the supplied options. $this->options = array_merge($this->options, $options); // Debug $this->error("Logging in as {$email} to {$this->options['alias']}."); $url_header = @get_headers($this->getUrl()); if ($url_header[0] == 'HTTP/1.1 404 Not Found' || !$url_header) { return false; } // Authenticating and save session key $authClient = new SoapClient($this->getUrl(), $this->soap_options); $response = $authClient->AuthenticateWebSafe(array('email' => $email, 'pass' => $pass)); // Bad login case if ($response->AuthenticateWebSafeResult->Code == "Not_Found") { return false; } else { if ($response->AuthenticateWebSafeResult->Code == "Success") { // Save the session key in class and session $this->VeetroSession = $response->AuthenticateWebSafeResult->SessionKey; $this->User = $response; $this->session('VeetroSession', $this->VeetroSession); $this->session('UserID', (string) $response->AuthenticateWebSafeResult->User->EntityID); $this->session('User', $response->AuthenticateWebSafeResult->User); $this->error("Saving new session key {$this->VeetroSession}."); // Connect to api with VeetroHeader. $this->connect(); return true; } else { $this->error("Unknown auth response code: {$response->AuthenticateWebSafeResult->Code}", self::ERROR); die(print_r($response, true)); } } }
function ping_search_system() { global $site_link; $url = ''; $last_ping = get_option('last_ping_search_system') != false ? get_option('last_ping_search_system') : 0; $limit_time = time() - $last_ping > 3600; //limit time 3600 sm - 1 hour; if (count($_POST) > 1 && $limit_time) { foreach ($_POST as $key) { switch ($key) { case 'google_ping': $url = '//google.com/webmasters/sitemaps/ping?sitemap='; break; case 'yandex_ping': $url = '//webmaster.yandex.ru/wmconsole/sitemap_list.xml?host='; break; case 'yahoo_ping': $url = '//search.yahooapis.com/SiteExplorerService/V1/ping?sitemap='; break; case 'bing_ping': $url = '//www.bing.com/webmaster/ping.aspx?siteMap='; break; case 'ask_ping': $url = '//submissions.ask.com/ping?sitemap='; break; } if (@get_headers($url)) { wp_remote_get($url . $site_link . "sitemap.xml"); } } update_option('last_ping_search_system', time()); } }
public function get($url) { /*$curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curl); curl_close($curl); return $data;*/ $page_headers = @get_headers($url); if ($page_headers[0] == 'HTTP/1.1 404 Not Found') { return array('success' => false); } $page = file_get_contents($url); $dom = new DOMDocument(); @$dom->loadHTML($page); $metas = $dom->getElementsByTagName('meta'); $data = array('title' => '', 'description' => '', 'image' => '', 'success' => true); foreach ($metas as $meta) { if ($meta->getAttribute('property') == 'title' || $meta->getAttribute('property') == 'og:title' || $meta->getAttribute('name') == 'twitter:title') { $data['title'] = $meta->getAttribute('content'); } if ($meta->getAttribute('property') == 'description' || $meta->getAttribute('property') == 'og:description' || $meta->getAttribute('name') == 'twitter:description') { $data['description'] = $meta->getAttribute('content'); } if ($meta->getAttribute('property') == 'og:image' || $meta->getAttribute('name') == 'twitter:image:src') { $data['image'] = $meta->getAttribute('content'); } } if ($data['title'] == '' && $data['description'] == '' && $data['image'] == '') { return array('success' => false); } return $data; }