Guest User

Untitled

a guest
Nov 25th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <?php
  2. require(&#039;connect.php&#039;);
  3. session_start():
  4.  
  5. $error = mysql_error();
  6.  
  7. // check if a user is online, returns true or false.
  8. function is_online($username) {
  9.  
  10. // grab the value of the field logged_in
  11. $select_query = mysql_query("SELECT * FROM users WHERE username=&#039;$username&#039;");
  12.  
  13. if ($select_query){
  14. while($entry = mysql_fetch_assoc($select_query)) {
  15. $logged_in = $entry[&#039;logged_in&#039;];
  16. }
  17.  
  18. // return the number of rows from select_query
  19. return $logged_in;
  20. } else {
  21. die($error);
  22. }
  23. }
  24.  
  25. function check_user($username){
  26. $check_query = mysql_query("SELECT * FROM users WHERE username=&#039;$username&#039;");
  27. $username_exists = mysql_num_rows($check_query);
  28.  
  29. return $username_exists;
  30. }
  31.  
  32. function check_email($email){
  33. $check_query = mysql_query("SELECT * FROM users WHERE email=&#039;$email&#039;");
  34. $username_exists = mysql_num_rows($check_query);
  35.  
  36. return $email_exists;
  37. }
  38.  
  39. function register_user($username, $pwd, $email, $fname, $lname, $town, $dob, $lvl, $about, $interests, $xp, $avatar) {
  40. // add the data to the database
  41. $add_to_db = mysql_query("INSERT INTO users values(&#039;&#039;,&#039;$username&#039;,&#039;$pwd&#039;,&#039;$email&#039;,&#039;$fname&#039;,&#039;$lname&#039;,&#039;$town&#039;,&#039;$dob&#039;,&#039;$lvl&#039;,&#039;$about&#039;,&#039;$interests&#039;,&#039;$xp&#039;,&#039;$avatar&#039;)");
  42.  
  43. if (!$add_to_db) {
  44. die($error);
  45. } else {
  46. // return true or false
  47. return $add_to_db;
  48. }
  49. }
  50.  
  51. function login($username, $pwd) {
  52. // encryption
  53. $hashedpwd = crypt(crypt(sha1(md5($pwd)),md5(sha1($pwd))), md5($pwd));
  54.  
  55. // Query to select the username and password, and if it exists, log in
  56. $check_db_login_data = mysql_query("SELECT * FROM users WHERE username=&#039;$username&#039; AND password=&#039;$hashedpwd&#039;");
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63. function generate_avatar_link($filename){
  64.  
  65. // take the filename and add random numbers at the end.
  66. $scrambled_filename = $filename . mt_rand();
  67.  
  68. // then MD5 it(for fun)
  69. $md5ed = md5($scrambled_filename);
  70.  
  71. // then add the extension, making it a 36 char long filename.
  72. $newfilename = $md5ed + ".png";
  73.  
  74. // then return it back from where it came!
  75. return $newfilename;
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. ?>
Add Comment
Please, Sign In to add comment