views:

99

answers:

1

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

+1  A: 

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;

?>
icio
It works fine with remote files, it works with any url I input EXCEPT an IP. Thank you though.
Rob
Then again, trying that couldn't hurt, if anything to see if its md5_file() causing the problem. Give me a moment
Rob
Well while this didn't solve the problem, it did help me realize it wasn't a problem with the function. I tried to use cURL and even lynx, and it seems it just times out. Which is odd, but eh, different problem then. Thanks for the help. And for future reference for you, since its always good to learn new things, md5_file() **DOES** work with remote files.
Rob