Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <?php
  2.  
  3. /* begin session */
  4. session_start();
  5.  
  6. /*first check that both the username,password and form token have been sent */
  7.  
  8. if(!isset($_POST['user_login'], $_POST['pass']))
  9. {
  10. return 'please enter a valid username and password';
  11. }
  12.  
  13. /* check the form token is valid */
  14.  
  15. elseif
  16. ($_POST['register'] != $_SESSION['register'])
  17. {
  18. return 'invalid for submission';
  19. }
  20.  
  21.  
  22. else{
  23.  
  24. $user_login= filter_var($_POST['user'], FILTER_SANITIZE_STRING);
  25. $pass = filter_var($_POST['pwd'], FILTER_SANITIZE_STRING);
  26.  
  27. /*Encrypt password */
  28. /* $pass = sha1 ($pass); */
  29.  
  30. /*connect to the db */
  31.  
  32. $mysql_hostname='localhost';
  33. $mysql_username='james';
  34. $mysql_password='password';
  35. $mysql_dbname='king_db';
  36.  
  37. try {
  38.  
  39.  
  40. //conection to the database
  41. $dbh = new PDO('mysql:host=localhost;dbname=king_db;charset=utf8', 'james', 'password');
  42. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  43.  
  44. // prepare statement for the selection of data from my sql tables
  45. $statement = $dbh->prepare('INSERT INTO logins (email, password) VALUES (:user_login , passwrd)');
  46. //binds the email coloum to the user_login input for checking data
  47. $statement->bindParam(':email', $_POST['user_login'], PDO::PARAM_STR);
  48.  
  49. // this statement is not needed, when you encrypt passwords it dose not following the exact same string
  50. $statement->bindParam(':password', $_POST['passwrd'], PDO::PARAM_STR);
  51.  
  52. //executes the above statments
  53. $statement->execute();
  54.  
  55. unset($_SESSION['register']);
  56.  
  57. // is a statment that fetches the array from the databaese, the fetch_assoc only pulls the data that
  58. // has the string of the the coloum name with it instead of the both the ones with ids ie [email] fadf@dfa.com, or [1]fadf@fads.com
  59. $results = $statement->fetchAll(PDO::FETCH_ASSOC);
  60.  
  61.  
  62. //setting a session for 'email' then
  63. $_SESSION['register'] = $_POST['adduser'];
  64.  
  65.  
  66. //echoing the $session
  67. echo "<pre>";
  68. print_r($_SESSION);
  69. echo "</pre>";
  70. }
  71. //catches the try statment in other terms stop the error reporting.
  72. catch (Exception $e)
  73. {
  74. echo $e->getMessage();
  75. // check if username already exists
  76. //($e->getCode() ==23000)
  77. //{
  78. /** if we are here, something has gone wrong with your database */
  79. // $message= 'we are unable to process your request. please try agin later';
  80. //echo 'Error:';
  81.  
  82.  
  83. }
  84. }
  85.  
  86. ?>
  87.  
  88. <html>
  89. <head>
  90. <title> King Login </title>
  91. </head>
  92. <body>
  93. <p>
  94. <?php
  95.  
  96. ?>
  97. </p>
  98. </body>
  99. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement