#1
  1. No Profile Picture
    markdrayton
    Guest
    Devshed Newbie (0 - 499 posts)
    I am creating a site which connects to specified URLs, makes a MD5 checksum of the contents and then checks it against the database to see if it has been changed. The browser stops when the file should be opened and dies. The code all works except for this function. Can someone point out any obvious mistakes and/or make suggestions on how to improve it.

    (Please forgive bad code - new programmer!)

    function hash($addr,$hashold,$hashid) {
    if ($inputfile = @fopen($addr,"r")) {
    $string = "";
    while ($line = fgets($inputfile, 4096)) {
    $string = $string. $line;
    }
    fclose($inputfile);
    $hashbin = mhash(MHASH_SHA1, "$string");
    $hashhex = bin2hex($hashbin);
    if ($hashhex == $hashold) {
    print "<td width=50></td>n";
    } else {
    mysql_query("update data set hash='$hashhex' where id='$hashid'");
    print "<td width=50>NEW! </td>n";
    }
    } else {
    print "<td width=50>??? </td>";
    }
    }

    Thanks
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    I don't see anything wrong but I may have missed something. I see you are using some table tags. Are you using Netscape as your browser? If so, then you need to "view source" when your browser "dies". If there is no closing </table> tag, Netscape won't display the table. This means that if your script encounters an error between <table> and </table> you won't see the error message. Use IE to look at it or use "view source" in Netscape to see if there is an error message.

    HTH

    Rod
  4. #3
  5. No Profile Picture
    markdrayton
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks. The table thing is just because it's all in a [badly written] function called during a table being built. I have since 'rearranged' it so that the hashing updates a field in the database to be displayed with the rest of the table later in the script.

    The odd thing is that I have made a small script to open a URL (basically the same scipt up without the hashing) and then spit out $string which works fine. In the apache access log I see the GET <URL> okay, but not with the above. I'm at a loss...
  6. #4
  7. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Another suggestion. Remove the @ in the fopen to remove error suppression so you can see if there is an error being reported.
  8. #5
  9. No Profile Picture
    markdrayton
    Guest
    Devshed Newbie (0 - 499 posts)
    I tried that - it seems that it's not getting that far, or at least it's not reporting an error. I'm running Apache 1.3.9 and PHP 3.0.11 on RH6. Are there any config files which could restrict me from opening other URLs?

    When I use Lynx, I get:

    Looking up host...
    Sending HTTP request...

    and it just hangs here. The apache log shows nothing.

    Thanks for any help!
  10. #6
  11. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Are you sure you're even getting to the function? Add:

    print "so far so good";

    as the first line of the function.

    If that doesn't come out then you know the problem isn't the function.
  12. #7
  13. No Profile Picture
    markdrayton
    Guest
    Devshed Newbie (0 - 499 posts)
    Okay, problem solved. It was all my fault, a bad SQL query was trying to connect my machine (not on the net) to some external website. I *thought* my script could handle this...something for another day!

    Thanks Rod K!

Similar Threads

  1. hash problems
    By morgano in forum Perl Programming
    Replies: 1
    Last Post: January 27th, 2004, 12:10 PM
  2. sort problem with hash
    By kpolillo in forum Perl Programming
    Replies: 2
    Last Post: October 30th, 2003, 01:34 AM
  3. Opening Files using a PHP url
    By HAOS in forum PHP Development
    Replies: 2
    Last Post: September 15th, 2003, 01:51 AM
  4. loadingVariables & opening URL
    By nebrekab in forum Flash Help
    Replies: 3
    Last Post: September 4th, 2003, 10:04 AM
  5. Issue with URL address using LWP
    By usaindp1776 in forum Perl Programming
    Replies: 4
    Last Post: September 3rd, 2003, 07:51 PM

IMN logo majestic logo threadwatch logo seochat tools logo