PHP and Google Safe Browsing Version 2 Examples Required

midnite Purr

New Member
Im looking to develop a PHP application which uses the Google Safe Browsing (GSB) Version 2. I have searched but some of the provided URL does not exist. I am looking for example code on how to make this work. This code use to work but it seems that it is not compatible with version 2. Help on this matter would be appreciated.\[code\]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Google Safe browsing</title> </head> <body> <?php $conn = mysql_connect('localhost', 'username', 'password') or die(mysql_error());mysql_select_db('dbname') or die(mysql_error());$api_key = "api-key";$version = "goog-malware-hash";$google_url = "http://sb.google.com/safebrowsing/update";//open the remote URL$target = "$google_url?client=api&apikey=$api_key&version=$version:1:-1";$handle = fopen("$target", 'r') or die("Couldn't open file handle " . $target);//populate the dbif ($handle) { echo "<img src='http://stackoverflow.com/questions/10546125/loading-gif-animation.gif' alt='Loading' />"; while (!feof($handle)) { $line = fgets($handle); //ignore the line [goog-malware-hash 1.14879] if (substr($line,0,1) != '[') { $operation = (substr($line,0,1)); //get the '+' or '-' $hash = substr($line,1); //get the md5 hash $hash = mysql_real_escape_string($hash); //just to be safe if ($operation == '+') $sql = 'insert into malware set ' . 'malware_hash = \'' . $hash . '\''; else $sql = 'delete from malware ' . 'where malware_hash = \'' . $hash . '\''; mysql_query($sql) or die(mysql_error()); } } fclose($handle);}mysql_close($conn);echo "Completed!";?> </body> </html></code>\[/code\]
 
Back
Top