PHP Script for Accessing VirusTotal API Version 2.0

Recently VirusTotal updated its API to version 2.0. As the version 1.0 is now deprecated, I have also updated my PHP script for accessing this API:

Download PHP script for accessing VirusTotal API version 2.0

For a detailed description of this API implementation, please have a look on my post about VirusTotal API version 1.0.

Let me know if you have any questions or problems using this PHP API script.

This post is also available in Deutsch.

15 thoughts on “PHP Script for Accessing VirusTotal API Version 2.0

  1. I try use your script but i have two errors :
    PHP Warning: mime_content_type(): File or path not found ‘WinXP_Mirc_Fix.exe’ in /var/tmp/VirusTotalApiV2.php on line 48
    PHP Fatal error: Call to undefined function curl_init() in /var/tmp/VirusTotalApiV2.php on line 261

    Did i miss something ?

    • Hello Azfayel,

      first obviously the script does not find your file and second this script needs the PHP curl extension to be installed and activated.

      Best regards
      Andreas

  2. I tried using this one for URL scanning, and no matter what URL I choose, it always throws -1 -1 -1 using the following:

    $api = new VirusTotalAPIV2(‘mykey’);
    $return = $api->getURLReport(‘http://www.google.com',TRUE);
    $api->displayResult($report);
    print($api->getTotalNumberOfChecks($report) . ”);
    print($api->getNumberHits($report) . ”);
    print($api->getReportPermalink($report, FALSE) . ”);

    • Oh, forgot to mention that I checked that the API key was the correct one. Even tested it using a second key.

      Any ideas??

      Thanks!

      • Hello FE,

        I’ve tested it again right now and the script works fine also for scanning URLs with the parameters you’re using.

        The result code “-1″ means that there is something wrong with your API key (“you do not have the required privileges”). Maybe you’re tying to use an API key from version 1 for the version 2 API?

        Best regards
        Andreas

        • Thank you for your reply, that was fast :P

          I am using the key provided under my profile > API Key…

          Is there any other API key?

          Thank you!

  3. Hello Mr Andreas Breitschopp,

    for more that 3 months, your php script for virustotal API2 was working fine, but nowadays, I dont know what happened , it does’t work and actually I got timeout error message, which means that there is no response from virsutotal website.

    my curl is OK, and I tried to use another Public API by using a new account , but that problem still,
    And I need you Help
    Thank a lot.

    • Hello Nasser,

      sorry, but I don’t what the problem is either, but a timeout error message does not sound like a problem with this PHP script, but more with e. g. the API server. Therefore maybe you should ask VirusTotal about this issue.

      Best regards
      Andreas

  4. Hello Mr Andreas Breitschopp,

    There is a point I want to make sure. I use virustotal php api to upload my files for scanning. I find that when I get associated reports, I will get the results of previous analysis, right!? Given the condition, is there any method could I use the virustotal php api to do the “Reanalysis” action (get the lately scanned results)?

    Best regards
    Patrick

    • Hello Patrick,

      as far as I know files are always rescanned when you’re submitting them through the API.

      But keep in mind that scanning may take several hours till it has been completed. Therefore you should check some hours after submitting again if you get a newer scan report then.

      Best regards
      Andreas

  5. Is someone able to use the API to test URls? I always get “-1″ no matter what I try (different API keys, different URls, etc).

    Thanks!

  6. Pingback: VirusTotal service API always returns response code 1 | Sudhir Tiwari | Sudhir Tiwari

  7. Hi Andreas

    Using PHP v5.4.7
    Using this version I get
    “Fatal error: Call to undefined function mime_content_type() in C:\xampp\htdocs\SSAM_1.5.3\virus_total\VirusTotalApiV2.php on line 48″

    mime_content_type() has been deprecated in favour of Fileinfo

    To quote from PHP manual: “This function has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.”

    I can’t see a simple way of fixing this error. Do you have any advice on the matter?

    I’ve also tried using PHP v5.2.x and it is working ok. Not sure at which point this was deprecated.

    Regards

Leave a Reply to Nasser Cancel reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>