note 85246 added to function.file-exists

From: Date: Thu, 21 Aug 2008 19:07:10 +0000
Subject: note 85246 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-143722@lists.php.net to get a copy of this message
Small adjustment to the url_exist() by marufit at gmail dot com. Some sites like digg.com for example check the HTTPHEADER to see who is requesting the page and will PHP will throw an error. Adding the following line fixes the issue: curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox <?php function url_exists($url) { // Version 4.x supported $handle = curl_init($url); if (false === $handle) { return false; } curl_setopt($handle, CURLOPT_HEADER, false); curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox curl_setopt($handle, CURLOPT_NOBODY, true); curl_setopt($handle, CURLOPT_RETURNTRANSFER, false); $connectable = curl_exec($handle); curl_close($handle); return $connectable; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 67.35.87.15 ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- https://master.php.net/note/edit/85246 Del: integrated -- https://master.php.net/note/delete/85246/integrated Del: useless -- https://master.php.net/note/delete/85246/useless Del: bad code -- https://master.php.net/note/delete/85246/bad+code Del: spam -- https://master.php.net/note/delete/85246/spam Del: non-english -- https://master.php.net/note/delete/85246/non-english Del: in docs -- https://master.php.net/note/delete/85246/in+docs Del: other reasons-- https://master.php.net/note/delete/85246 Reject -- https://master.php.net/note/reject/85246 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143722) next »