Advertisement
Guest User

Bad Code

a guest
Feb 19th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. include 'db_connection.php'; // Assume this external script connects us to the database
  4.  
  5. // Start session
  6. session_start();
  7.  
  8. // Extract POST variables: 'username', 'password', and 'filename'
  9. extract($_POST);
  10.  
  11. // Check if user is already logged in
  12. if ($_SESSION['is_logged_in'] == '1') {
  13.  
  14. // Output confidential file contents to user
  15. echo shell_exec('cat ~/confidential_info/' . $filename);
  16.  
  17. } else {
  18.  
  19. // Check login credentials
  20. $query =
  21. "SELECT * FROM users WHERE ".
  22. "username = '" . $username . "' AND ".
  23. "password = '" . $password . "';"
  24. $result = mysql_query($query);
  25.  
  26. if (mysql_num_rows($result) > 0) {
  27.  
  28. // Login information matched credentials!
  29. $_SESSION['is_logged_in'] = '1';
  30.  
  31. // Output confidential file contents to user
  32. echo shell_exec('cat ~/confidential_info/' . $filename);
  33.  
  34. } else {
  35.  
  36. // Login information did not match!
  37. die('You do not have access.');
  38.  
  39. }
  40. }
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement