We're using pubdlcnt to count the amount of downloads of files which are stored in an amazon S3 bucket. We're seeing a lot of notices in the error log:
[Mon May 31 18:55:05 2010] [error] [client 82.75.186.105] PHP Notice: Undefined variable: pos in /home/httpd/vhosts/thepartysquad.com/httpdocs/sites/default/modules/pubdlcnt/pubdlcnt.php on line 171, referer: http://www.thepartysquad.com/
This is the code that generates it. It doesn't seem that $pos is defined anywhere in the function. But i'm not sure on how the use of $pos was intended.
/**
* Function to check if the specified file URL really exists or not
*/
function url_exists($url) {
$a_url = parse_url($url);
if (!isset($a_url['port'])) $a_url['port'] = 80;
$errno = 0;
$errstr = '';
$timeout = 30;
if (isset($a_url['host']) && $a_url['host'] != gethostbyname($a_url['host'])) {
$fid = @fsockopen($a_url['host'], $a_url['port'], $errno, $errstr, $timeout);
if (!$fid) return false;
$page = isset($a_url['path']) ? $a_url['path'] : '';
$page .= isset($a_url['query']) ? '?' . $a_url['query'] : '';
fputs($fid, 'HEAD ' . $page . ' HTTP/1.0' . "\r\n" . 'HOST: '
. $a_url['host'] . "\r\n\r\n");
$head = fread($fid, 4096);
$head = substr($head, 0, strpos($head, 'Connection: close'));
fclose($fid);
// Here are popular status code back from the server
//
// URL exits 'HTTP/1.1 200 OK'
// URL exits (but redirected) 'HTTP/1.1 302 Found'
// URL does not exits 'HTTP/1.1 404 Not Found'
// Can not access URL 'HTTP/1.1 403 Forbidden'
// Can not access server 'HTTP/1.1 500 Internal Server Error
//
// So we return true only when status 200 or 302
if (preg_match('#^HTTP/.*\s+[200|302]+\s#i', $head)) {
return $pos !== false;
}
}
return false;
}
The counter works as intended, so it's no big problem, but it would be nice to fix this.
Comments
Comment #1
chalpin commented