Guest User

Untitled

a guest
Jan 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. $DB = new PDO('mysql:host=127.0.0.1;dbname=promo_usoft_ru', 'promo_usoft_ru', 'hTNzCtcjyYc5wXPS');
  4.  
  5.  
  6. $make = true;
  7.  
  8. while ($make) {
  9.     $sql = "SELECT * FROM `promo_codes`";
  10.     $STMNT = $DB->prepare($sql);
  11.     $STMNT->execute();
  12.  
  13.     if ( $STMNT->rowCount() < 1000 ) {
  14.  
  15.         $letters = array("a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "w", "x", "y", "z");
  16.         $strLenght = rand(5, 10);
  17.         $str = '';
  18.  
  19.         for ($i = 0; $i <= $strLenght; $i++) {
  20.             $letNum = rand(0, sizeof($letters));
  21.             $str = rand(0, 1000000000) . $letters[$letNum];
  22.         }
  23.  
  24.         $str = sha1($str);
  25.         $str = substr($str, 0, 6);
  26.  
  27.         $sql = "SELECT `id`
  28.                FROM `promo_codes`
  29.                WHERE `code` = ?";
  30.         $state = $DB->prepare($sql);
  31.         $state->execute(array($str));
  32.  
  33.         if ( $state->rowCount() == 0 && !strpos($str, 'e') ) {
  34.             $sql = "INSERT INTO `promo_codes`
  35.                    SET `code` = ?";
  36.             $state = $DB->prepare($sql);
  37.             $state->execute(array($str));
  38.         }
  39.  
  40.     } else {
  41.         $make = false;
  42.     }
  43.  
  44. }
Add Comment
Please, Sign In to add comment