Advertisement
Guest User

Untitled

a guest
Mar 5th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1.  
  2.  
  3. <!DOCTYPE HTML>
  4. <html>
  5. <head>
  6. <title>Sign-In</title>
  7. <link rel='stylesheet'type='text/css' href='style-sign.css'>
  8. </head>
  9. <body id='body-color'> <div id='Sign-In'>
  10. <fieldset style='width:30%'><legend>LOG-IN HERE</legend>
  11. <form method='POST'action='connectivity.php'>
  12. <br><input type='text' name='username' size='40'><br> Password
  13. <br><input type='password' name='pass' size='40'><br>
  14. <input id='button' type='submit' name='submit' value='Log-In'>
  15. </form>
  16. </fieldset>
  17. </div>
  18. </body>
  19. </html>
  20.  
  21. <a href='http://xxxxxxxxxxxxxxxxxxxxxxx/register.htm'>Register</a>
  22.  
  23. <?php
  24. require_once("connectivity.php");
  25.  
  26. try {
  27. /* Call connection to database function */
  28. $db = getConnection();
  29.  
  30. /* SQL Queries ---------------------------------------- */
  31.  
  32. /*Request the post functions from the loginForm.php */
  33. $username = $_REQUEST['user'];
  34. $password = $_REQUEST['pass'];
  35. $sublogin = $_REQUEST['sublogin'];
  36.  
  37. $sql="SELECT * FROM user WHERE email ='$username'
  38. AND pass='".md5($_POST['pass'])."'";
  39. $password['pass'];
  40. $query = $db->query( $sql );
  41.  
  42. if (count($db->$query)>0) {
  43. //Login Successful . Update the database, adding timestamp of last time member logged in.
  44. $db->query("UPDATE user SET lastlogin='". date("Y-m-d H:i:s",time())."' where email='".$_SESSION['username']."' and password='".$_SESSION['password']."'");
  45.  
  46. $username = $db->fetch($result);
  47. $_SESSION['username']=$username['username'];
  48. $_SESSION['password']=$password['password'];
  49. //Write session to disc
  50. session_write_close();
  51. header("location: test2.php");
  52. exit();
  53. }
  54. if(isset($_POST['sublogin'])){
  55. /* Check that all fields were typed in */
  56. if(!$_POST['user'] || !$_POST['pass']){
  57. die('You didn\'t fill in a required field.');
  58. }
  59.  
  60. /* Checks that email is in database and password is correct */
  61. $md5pass = md5($_POST['pass']);
  62. $result = confirmUser($_POST['user'], $md5pass);
  63.  
  64. /* Check error codes */
  65. if($result == 1){
  66. die('That username doesn\'t exist in our database.');
  67. }
  68. else if($result == 2){
  69. die('Incorrect password, please try again.');
  70. }
  71.  
  72. /* email and password correct, register session variables */
  73. $_POST['user'] = $_POST['user'];
  74. $_SESSION['username'] = $_POST['user'];
  75. $_SESSION['password'] = $md5pass;
  76. }
  77. }
  78. catch( PDOException $e ) {
  79. echo $e->getMessage();
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement