Guest User

Untitled

a guest
Feb 26th, 2015
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. $db_username = "peoplein"; //Input your database username here
  3. $db_password = "xxxxxxx"; //Input your database password here
  4. $db_host = "localhost"; //Input your database host here
  5. $db_name = "xxxxxxxx"; //Input your database name here
  6.  
  7. $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
  8.  
  9. try {
  10. $connection = new PDO("mysql:host={$db_host};dbname={$db_name};charset=utf8", $db_username, $db_password, $options);
  11. $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. }
  13.  
  14. catch(PDOException $ex) {
  15. echo "Cannot connect to database.";
  16. }
  17.  
  18. header('Content-Type: text/html; charset=utf-8');
  19. ?>
  20.  
  21. <!doctype html>
  22. <html>
  23. <head>
  24. <title>Login</title>
  25. </head>
  26. <body>
  27.  
  28. <?php
  29.  
  30. if (isset($_POST["user"])) {
  31. $user = $_POST["user"];
  32. }
  33. else {
  34. $user = "";
  35. }
  36. if (isset($_POST["pass"])) {
  37. $pass = $_POST["pass"];
  38. }
  39. else {
  40. $pass = "";
  41. }
  42.  
  43. $query="SELECT * FROM login WHERE username=:username";
  44.  
  45. $params=(array(':username' => $user));
  46.  
  47. try{
  48. $stmt = $connection->prepare($query);
  49. $result = $stmt->execute($params);
  50. }
  51.  
  52. catch(PDOException $ex){
  53. echo ("Failed to run query: " . $ex->getMessage());
  54. }
  55.  
  56. $fetch = $stmt->fetch();
  57. $passwordfetch=$fetch['password'];
  58.  
  59. if ($pass == $passwordfetch)) {
  60. session_start();
  61. $_SESSION['sess_user']=$user;
  62. ?>
  63. <meta http-equiv='refresh' content="0; url=http://peopleinvestment.ro/filip/admin.php">
  64. <?php
  65. }
  66. else {
  67. echo "Invalid Information";
  68. }
  69.  
  70. ?>
  71.  
  72. <center>
  73. <h3>Login</h3>
  74. <form action="" method="POST">
  75. Username: <input type="text" name="user">
  76. Password: <input type="password" name="pass">
  77. <input type="submit" value="Login" name="submit" />
  78. </form>
  79.  
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment