Guest User

Untitled

a guest
Jul 11th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. register--
  2.  
  3.  
  4.  
  5. <?php
  6.  
  7. // dbConfig.php is a file that contains your
  8. // database connection information. This
  9. // tutorial assumes a connection is made from
  10. // this existing file.
  11. include ("dbConfig.php");
  12.  
  13.  
  14. //Input vaildation and the dbase code
  15. if ( $_GET["op"] == "reg" )
  16. {
  17. $bInputFlag = false;
  18. foreach ( $_POST as $field )
  19. {
  20. if ($field == "")
  21. {
  22. $bInputFlag = false;
  23. }
  24. else
  25. {
  26. $bInputFlag = true;
  27. }
  28. }
  29. // If we had problems with the input, exit with error
  30. if ($bInputFlag == false)
  31. {
  32. die( "Problem with your registration info. "
  33. ."Please go back and try again.");
  34. }
  35.  
  36. // Fields are clear, add user to database
  37. // Setup query
  38. $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  39. ."VALUES ('".$_POST["username"]."', "
  40. ."PASSWORD('".$_POST["password"]."'), "
  41. ."'".$_POST["email"]."')";
  42. // Run query
  43. $r = mysql_query($q);
  44.  
  45. // Make sure query inserted user successfully
  46. if ( !mysql_insert_id() )
  47. {
  48. die("Error: User not added to database.");
  49. }
  50. else
  51. {
  52. // Redirect to thank you page.
  53. Header("Location: register.php?op=thanks");
  54. }
  55. } // end if
  56.  
  57.  
  58. //The thank you page
  59. elseif ( $_GET["op"] == "thanks" )
  60. {
  61. echo "<h2> Thanks for registering!</h2> ";
  62. }
  63.  
  64. //The web form for input ability
  65. else
  66. {
  67. echo "<form action=\"?op=reg\" method=\"POST\"> \n";
  68. echo "Username: <input name=\"username\" MAXLENGTH=\"16\"> <br /> \n";
  69. echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"> <br /> \n";
  70. echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"> <br /> \n";
  71. echo "<input type=\"submit\"> \n";
  72. echo "</form> \n";
  73. }
  74. // EOF
  75. ?>
  76.  
  77.  
  78. db config ---
  79.  
  80. <?
  81. // Replace the variable values below
  82. // with your specific database information.
  83. $host = "(local)";
  84. $user = "sa";
  85. $pass = "123456";
  86. $db = "AccountServer";
  87.  
  88. // This part sets up the connection to the
  89. // database (so you don't need to reopen the connection
  90. // again on the same page).
  91. $ms = mysql_pconnect($host, $user, $pass);
  92. if ( !$ms )
  93. {
  94. echo "Error connecting to database.\n";
  95. }
  96.  
  97. // Then you need to make sure the database you want
  98. // is selected.
  99. mysql_connect($db);
  100. ?>
  101.  
  102. login --
  103. <?php
  104. session_start();
  105. // dBase file
  106. include "dbConfig.php";
  107.  
  108. if ($_GET["op"] == "login")
  109. {
  110. if (!$_POST["username"] || !$_POST["password"])
  111. {
  112. die("You need to provide a username and password.");
  113. }
  114.  
  115. // Create query
  116. $q = "SELECT * FROM `dbUsers` "
  117. ."WHERE `username`='".$_POST["username"]."' "
  118. ."AND `password`=PASSWORD('".$_POST["password"]."') "
  119. ."LIMIT 1";
  120. // Run query
  121. $r = mysql_query($q);
  122.  
  123. if ( $obj = @mysql_fetch_object($r) )
  124. {
  125. // Login good, create session variables
  126. $_SESSION["valid_id"] = $obj->id;
  127. $_SESSION["valid_user"] = $_POST["username"];
  128. $_SESSION["valid_time"] = time();
  129.  
  130. // Redirect to member page
  131. Header("Location: members.php");
  132. }
  133. else
  134. {
  135. // Login not successful
  136. die("Sorry, could not log you in. Wrong login information.");
  137. }
  138. }
  139. else
  140. {
  141. //If all went right the Web form appears and users can log in
  142. echo "<form action=\"?op=login\" method=\"POST\">";
  143. echo "Username: <input name=\"username\" size=\"15\"><br />";
  144. echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  145. echo "<input type=\"submit\" value=\"Login\">";
  146. echo "</form>";
  147. }
  148. ?>
Add Comment
Please, Sign In to add comment