Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. root@dev:/var/www/html/php# cat server.php
  2. <?php
  3.  
  4. ini_set('display_errors',1); error_reporting(E_ALL);
  5.  
  6. $host = "host=localhost";
  7. $dbname = "dbname=server";
  8. $creds = "user=postgres password=postgres";
  9.  
  10. // connect to the database
  11. $db = pg_connect("$host $dbname $creds");
  12.  
  13.  
  14. // if the register button is clicked
  15. if(isset($_POST['register'])) {
  16. $username = $_POST['username'];
  17. $password1 = $_POST['password'];
  18. $password2 = $_POST['password_2'];
  19.  
  20. // ensure that form fields are filled properly
  21. if (empty($username)) {
  22. array_push($errors, "Username is required.");
  23. }
  24. if (empty($password_1)) {
  25. array_push($errors, "Passphrase is required.");
  26. }
  27. if ($password_1 != $password_2) {
  28. array_push($errors, "The two passwords don't match.");
  29. }
  30. }
  31. // if there are no errors, save user to database
  32. if (count($errors) == 0) {
  33. $password = md5($password_1); // encrypt password before storing
  34. $sql = <<<EOF
  35. INSERT INTO username (username, password)
  36. VALUES ('$username','$password');
  37. EOF;
  38.  
  39.  
  40. $ret = pg_query($db, $sql);
  41. if(!$ret) :
  42. echo pg_last_error($db);
  43. else :
  44. exit("Table created successfully!".PHP_EOL);
  45. endif;
  46. ?>
  47.  
  48. =================================================================
  49.  
  50. root@dev:/var/www/html/php# cat index.php
  51.  
  52. <html>
  53. <body>
  54.  
  55. <form action="register.php" method="post">
  56. Username: <input type="text" name="username"><br>
  57. Password: <input type="password" name="password"><br>
  58. Confirm Password: <input type="password" name="password_2"><br>
  59. <input type="submit" >
  60. </form>
  61.  
  62. </body>
  63. </html>
  64.  
  65. <?php
  66. require('server.php');
  67. ?>
  68.  
  69.  
  70. ======================================================================
  71.  
  72. root@dev:/var/www/html/php# cat register.php
  73. <?php
  74.  
  75.  
  76. echo "<h1> YOU ENTERED THE FOLLOWING </h1><br>";
  77. echo "username: ".$_POST["$username"]."<br>";
  78. echo "username: ".$_POST["$password"]."<br>";
  79. ?>
  80. <html>
  81. <h1> Thanks for registering! </h1>
  82. </html>
  83.  
  84. <?php require("server.php");?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement