Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. include('/scripts/dbh.php');
  3.  
  4. function generateRandomString($length = 50) {
  5. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6. $charactersLength = strlen($characters);
  7. $randomString = '';
  8. for ($i = 0; $i < $length; $i++) {
  9. $randomString .= $characters[rand(0, $charactersLength - 1)];
  10. }
  11. return $randomString;
  12. }
  13. if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])){
  14. die('Error! You did not enter a valid email address! Try again');
  15. }
  16. if(empty($_POST['first']) || empty($_POST['last']) || empty($_POST['uid']) || empty($_POST['password'])) {
  17. die('Error! You did not enter one or more of the requested fields. Please try again');
  18. }
  19. $first = mysqli_real_escape_string($conn, htmlentities($_POST['first']));
  20. $last = mysqli_real_escape_string($conn, htmlentities($_POST['last']));
  21. $username = mysqli_real_escape_string($conn, htmlentities($_POST['uid']));
  22. $password = mysqli_real_escape_string($conn, md5(htmlentities($_POST['password'])));
  23. $email = mysqli_real_escape_string($conn, strtolower(htmlentities($_POST['email'])));
  24. $unid = md5(generateRandomString());
  25. $grp = 'user';
  26. $msg = 'message';
  27.  
  28. $msg = wordwrap($msg,70);
  29.  
  30. $headers = 'MIME-Version: 1.0' . "\r\n";
  31. $headers .= 'From: ex signup' . "\r\n";
  32. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  33.  
  34. mail($email,"Welcome to example",$msg,$headers);
  35.  
  36. $conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);
  37.  
  38. if ($conn->connect_error) {
  39. die("Connection failed: " . $conn->connect_error);
  40. }
  41.  
  42. $sql = "INSERT INTO accounts (first, last, email, username, password, unid, grp)
  43. VALUES ('$first', '$last', '$email', '$username', '$password', '$unid', '$grp')";
  44.  
  45. if ($conn->query($sql) === TRUE) {} else {
  46. die("An Error has occured. Contact an admin.");
  47. }
  48.  
  49. $conn->close();
  50. header('Location: /login?messageid=0001');
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement