Guest User

form_throttle

a guest
Jan 15th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.83 KB | None | 0 0
  1. <?php
  2. /*  
  3. If you see this text in your browser, PHP is not configured correctly on this hosting provider.
  4. Contact your hosting provider regarding PHP configuration for your site.
  5.  
  6. PHP file generated by Adobe Muse CC 2015.0.2.310
  7. */
  8.  
  9. function formthrottle_check()
  10. {
  11.     if (!is_writable('.'))
  12.     {
  13.         return '8';
  14.     }
  15.  
  16.     try
  17.     {
  18.         if (in_array("sqlite",PDO::getAvailableDrivers(),TRUE))
  19.         {
  20.             $db = new PDO('sqlite:muse-throttle-db.sqlite3');
  21.             if ( file_exists('muse-throttle-db') )
  22.             {
  23.                 unlink('muse-throttle-db');
  24.             }
  25.         }
  26.         else if (function_exists("sqlite_open"))
  27.         {
  28.             $db = new PDO('sqlite2:muse-throttle-db');
  29.             if ( file_exists('muse-throttle-db.sqlite3') )
  30.             {
  31.                 unlink('muse-throttle-db.sqlite3');
  32.             }
  33.         }
  34.     }
  35.     catch( PDOException $Exception ) {
  36.         return '9';
  37.     }
  38.  
  39.     $retCode ='5';
  40.     if ($db)
  41.     {
  42.         $res = $db->query("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Submission_History';");
  43.         if (!$res or $res->fetchColumn() == 0)
  44.         {
  45.             $created = $db->exec("CREATE TABLE Submission_History (IP VARCHAR(39), Submission_Date TIMESTAMP)");
  46.  
  47.             if($created == 0)
  48.             {
  49.                 $created = $db->exec("INSERT INTO Submission_History (IP,Submission_Date) VALUES ('256.256.256.256', DATETIME('now'))");
  50.             }
  51.            
  52.             if ($created != 1)
  53.             {
  54.                 $retCode = '2';
  55.             }
  56.         }
  57.         if($retCode == '5')
  58.         {
  59.             $res = $db->query("SELECT COUNT(1) FROM Submission_History;");
  60.             if ($res && $res->fetchColumn() > 0)
  61.             {
  62.                 $retCode = '0';
  63.             }
  64.             else
  65.                 $retCode = '3';
  66.         }
  67.  
  68.         // Close file db connection
  69.         $db = null;
  70.     }
  71.     else
  72.         $retCode = '4';
  73.        
  74.     return $retCode;
  75. }  
  76.  
  77. function formthrottle_too_many_submissions($ip)
  78. {
  79.     $tooManySubmissions = false;
  80.  
  81.     try
  82.     {
  83.         if (in_array("sqlite",PDO::getAvailableDrivers(),TRUE))
  84.         {
  85.             $db = new PDO('sqlite:muse-throttle-db.sqlite3');
  86.         }
  87.         else if (function_exists("sqlite_open"))
  88.         {
  89.             $db = new PDO('sqlite2:muse-throttle-db');
  90.         }
  91.     }
  92.     catch( PDOException $Exception ) {
  93.         return $tooManySubmissions;
  94.     }
  95.  
  96.     if ($db)
  97.     {
  98.         $res = $db->query("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Submission_History';");
  99.         if (!$res or $res->fetchColumn() == 0)
  100.         {
  101.             $db->exec("CREATE TABLE Submission_History (IP VARCHAR(39), Submission_Date TIMESTAMP)");
  102.         }
  103.         $db->exec("DELETE FROM Submission_History WHERE Submission_Date < DATETIME('now','-2 hours')");
  104.         $stmt = $db->prepare("INSERT INTO Submission_History (IP,Submission_Date) VALUES (:ip, DATETIME('now'))");
  105.         $stmt->bindParam(':ip', $ip);
  106.         $stmt->execute();
  107.         $stmt->closeCursor();
  108.  
  109.         $stmt = $db->prepare("SELECT COUNT(1) FROM Submission_History WHERE IP = :ip;");
  110.         $stmt->bindParam(':ip', $ip);
  111.         $stmt->execute();
  112.         if ($stmt->fetchColumn() > 25)
  113.             $tooManySubmissions = true;
  114.         // Close file db connection
  115.         $db = null;
  116.     }
  117.     return $tooManySubmissions;
  118. }
  119. ?>
Add Comment
Please, Sign In to add comment