Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md5_file() not working with remote content fetched by URL

Here is my code relating to the question:

$theurl = trim($_POST['url']);
    $md5file = md5_file($theurl);
        if ($md5file != '96a0cec80eb773687ca28840ecc67ca1') { echo 'Hash doesn\'t match. Incorrect file. Reupload it and try again'; 

When I run this script, it doesn't even output an error. It just stops. It loads for a bit, and then it just stops.

Further down the script I implement it again, and it fails here, too:

while($row=mysql_fetch_array($execquery, MYSQL_ASSOC)){

$hash = @md5_file($row['url']);

$url = $row['url'];

mysql_query("UPDATE urls SET hash='" . $hash . "' WHERE url='" . $url . "'") or die("There was a problem: ".mysql_error());

        if ($hash != '96a0cec80eb773687ca28840ecc67ca1'){
            $status = 'down';
            }else{
            $status = 'up';
            }
mysql_query("UPDATE urls SET status='" . $status . "' WHERE url='" . $url . "'") or die("There was a problem: ".mysql_error());

            }

And it checks all the URL's just fine, until it gets to one with an IP instead of a domain, such as:

http://188.72.216.143/~waffle/udp.php

In which, again, the script then just loads for a bit, and then stops.

Any help would be much appreciated, if you need any more information just ask.

EDIT: It seems to work with SOME IP's, but not others

like image 399
Rob Avatar asked Dec 28 '22 18:12

Rob


1 Answers

I thought that md5_file worked only with local files. The documentation certainly doesn't mention requests or anything. If you get the file manually you can use md5 to calculate the hash of the document. Try giving it a whirl.

<?php

    $contents = file_get_contents('http://stackoverflow.com');
    $md5file = md5($contents);

    echo $md5file;

?>
like image 70
icio Avatar answered Dec 31 '22 11:12

icio