note 99109 added to function.is-file

From: Date: Wed, 28 Jul 2010 10:59:30 +0000
Subject: note 99109 added to function.is-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-171183@lists.php.net to get a copy of this message
Simple, stable and solid function to check URL's. Will return HTTP status code even on internal errors. K.I.S.S. --- <?php var_dump(URL_GetStatus("http://www.rb.no/")); // URL_GetStatus by Dmitry K Valberg // dv@rb.no // Checks URL and returns easy to use HTTP status codes. // // Will return on error: // 501 - URL syntax error, URL not valid. // 503 - Timeout, connection error etc. // // If url is valid and curl connected to server, //real HTTP code will be returned. function URL_GetStatus($url) { $_r = 501; if (filter_var($url, FILTER_VALIDATE_URL) != false) { try { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $url); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FAILONERROR, 1); @curl_setopt($ch, CURLOPT_NOBODY, 1); @curl_setopt($ch, CURLOPT_TIMEOUT, 5); @curl_exec($ch); $info = @curl_getinfo($ch); curl_close ($ch); if (($info['http_code'] > 100)) $_r = $info['http_code']; } catch (Exception $e) { $_r = 503; } } return $_r; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 193.215.6.253 ---- Manual Page -- http://www.php.net/manual/en/function.is-file.php Edit -- https://master.php.net/note/edit/99109 Del: integrated -- https://master.php.net/note/delete/99109/integrated Del: useless -- https://master.php.net/note/delete/99109/useless Del: bad code -- https://master.php.net/note/delete/99109/bad+code Del: spam -- https://master.php.net/note/delete/99109/spam Del: non-english -- https://master.php.net/note/delete/99109/non-english Del: in docs -- https://master.php.net/note/delete/99109/in+docs Del: other reasons-- https://master.php.net/note/delete/99109 Reject -- https://master.php.net/note/reject/99109 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171183) next »