Advertisement
Guest User

Untitled

a guest
May 19th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2. $connection = mysqli_connect("localhost", "data", "aaa");
  3.  
  4. $db = mysqli_select_db("dados", $connection);
  5. session_start();// Starting Session
  6.  
  7. $user_check=$_SESSION['login_user'];
  8.  
  9. $ses_sql=mysqli_query("select username from login where username='$user_check'", $connection);
  10. $row = mysqli_fetch_assoc($ses_sql);
  11. $login_session =$row['username'];
  12. if(!isset($login_session)){
  13. mysqli_close($connection); // Closing Connection
  14. header('Location: index.php'); // Redirecting To Home Page
  15. }
  16. ?>
  17.  
  18.  
  19. <?php
  20. session_start(); // Starting Session
  21. $error=''; // Variable To Store Error Message
  22. if (isset($_POST['submit'])) {
  23. if (empty($_POST['username']) || empty($_POST['password'])) {
  24. $error = "Username ou Password são inválidos";
  25. }
  26. else
  27. {
  28. // Define $username and $password
  29. $username=$_POST['username'];
  30. $password=$_POST['password'];
  31. // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  32. $connection = mysqli_connect("localhost", "data", "aaa");
  33. // Check connection
  34. //if ($connection->connect_error) {
  35. // die("Connection failed: " . $connection->connect_error);
  36. //}
  37. //echo "Connected successfully";
  38. // To protect MySQL injection for Security purpose
  39. $username = stripslashes($username);
  40. $password = stripslashes($password);
  41. $username = mysqli_real_escape_string($username);
  42. $password = mysqli_real_escape_string($password);
  43. // Selecting Database
  44. $db = mysqli_select_db("dados", $connection);
  45. // SQL query to fetch information of registerd users and finds user match.
  46. $query = mysqli_query("select * from login where password='$password' AND username='$username'", $connection);
  47. $rows = mysqli_num_rows($query);
  48. if ($rows == 1) {
  49. $_SESSION['login_user']=$username; // Initializing Session
  50. header("Location: menu.php"); // Redirecting To Other Page
  51. } else {
  52. $error = "Username ou Password são inválidosS";
  53. }
  54. mysqli_close($connection); // Closing Connection
  55. }
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement