Location: PHPKode > scripts > SHDetect > joshf-SHDetect-f0c6c96/detect.php
<?php

//SHDetect, Copyright Josh Fradley (http://github.com/joshf/SHDetect)

//Connect to database
require_once("config.php");

$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
    die("Could not connect: " . mysql_error());
}

mysql_select_db(DB_NAME, $con);

//Variables (received by GET) you set these during installation
$version = mysql_real_escape_string($_GET["version"]);
$field1 = mysql_real_escape_string($_GET["" . FIELD_1 . ""]);
$field2 = mysql_real_escape_string($_GET["" . FIELD_2 . ""]);
$field3 = mysql_real_escape_string($_GET["" . FIELD_3 . ""]);

//Check variables are not empty
if (empty($version)) {
    die("Version is missing...");
}
if (empty($field1)) {
    die("" . FIELD_1 . " is missing...");
}
if (empty($field2)) {
    die("" . FIELD_2 . " is missing...");
}
if (empty($field3)) {
    die("" . FIELD_3 . " is missing...");
}

//Prevent some injection attacks
if (!preg_match("/^[a-zA-Z0-9.-]{1,}$/", $version)) {
    die("Illegal character used..."); 
}
if (!preg_match("/^[a-zA-Z0-9.-]{1,}$/", $field1)) {
    die("Illegal character used..."); 
}
if (!preg_match("/^[a-zA-Z0-9.]{1,}$/", $field2)) {
    die("Illegal character used..."); 
}
if (!preg_match("/^[a-zA-Z0-9._]{1,}$/", $field3)) {
    die("Illegal character used..."); 
}

//Don't log dev versions
$string = "-dev";
$isdev = strpos($version, $string);

if ($isdev == true) {
    die("(" . APP_NAME . ") Dev version, not logging...");
} 

if (VERSION_RESPONSE_STATE == "Enabled") {
    if ($version != APP_VERSION) { 
        echo "1";
    } else {
        echo "0";
    }
} else {
    echo "(" . APP_NAME . ") $version $field1 $field2 $field3";
}

//Either add new data or update seen count
$checkifseen = mysql_query("SELECT * FROM Data WHERE Version = \"$version\" AND Field1 = \"$field1\" AND Field2 = \"$field2\" AND Field3 = \"$field3\"");
$checkifseenresult = mysql_num_rows($checkifseen);
if ($checkifseenresult != "0") { 
    mysql_query("UPDATE Data SET Count = Count+1 WHERE Version = \"$version\" AND Field1 = \"$field1\" AND Field2 = \"$field2\" AND Field3 = \"$field3\"");
} else { 
    mysql_query("REPLACE INTO Data (Version, Field1, Field2, Date, Field3, Count)
    VALUES (\"$version\",\"$field1\",\"$field2\",\"" . date("Y-m-d") . "\",\"$field3\",\"1\")");
}

mysql_close($con);

?>
Return current item: SHDetect