note 85246 deleted from function.file-exists by cmb

From: Date: Sun, 29 Sep 2019 07:14:23 +0000
Subject: note 85246 deleted from function.file-exists by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212381@lists.php.net to get a copy of this message
Note Submitter: justin ---- 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; } ?>

« previous php.notes (#212381) next »