Advertisement
Guest User

generate

a guest
Oct 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. define('HOST','localhost');
  3. define('PORT','3306');
  4. define('USER','root');
  5. define('PASS','');
  6. define('DB','rolling');
  7.  
  8. $link = new mysqli(HOST,USER,PASS,DB);
  9.  
  10. function GenerateSession(){
  11.     if ($link->connect_error) {
  12.     die('Error : ('. $link->connect_errno .') '. $link->connect_error);
  13.     }else{
  14.         $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  15.         $generate = substr(str_shuffle($permitted_chars), 0, 10);
  16.         $statement = $link->prepare("SELECT * FROM code WHERE code = ?");
  17.         $statement->bind_param("s", $code);
  18.         $code = GenerateSession();
  19.         $statement->execute();
  20.         $total_row = $statement->fetch_row();
  21.         if($total_row > 0 ){
  22.             return GenerateSession();
  23.         }else{
  24.             return $generate;
  25.             $state = $link->prepare("INSERT INTO code(code) VALUES(?)");
  26.             $state->bind_param("s", $generate);
  27.             $state->execute();
  28.         }
  29.         $statement->close()
  30.     }
  31. };
  32.  
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement