Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. function testarcode($code){
  2. global $link;
  3. if ($code == ""){
  4. return false;
  5. }
  6. $comando = "SELECT * FROM tbl_usuario WHERE code='$code'";
  7. $query = mysqli_query($link, $comando);
  8. if(mysqli_num_rows($query) > 0){
  9. return false;
  10. }
  11. else{
  12. return true;
  13. }
  14. }
  15.  
  16. function gerarcode(){
  17. $caracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  18. $max = strlen($caracteres) - 1;
  19. $code = "";
  20. while (testarcode($code) == false){
  21. for($i=0; $i < 5; $i++) {
  22. $code .= $caracteres[mt_rand(0, $max)];
  23. }
  24. }
  25. return $code;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement