Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2.  
  3. $dbc = mysqli_connect('127.0.0.1', '40076509', 'password', '40076509_news') or die('Error connecting to MySQL server');
  4.  
  5. if (empty($SESSION_['s_id']))
  6. {
  7. // Read the entered username and password
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. // Select password from database
  12. $loginresult = mysqli_query($dbc, "SELECT password FROM user WHERE username = '$username'") or die('Error accessing the user database');
  13. $row = mysqli_fetch_assoc($loginresult);
  14. if (mysqli_num_rows($loginresult) > 0 && password_verify($password, $row['password']))
  15. {
  16. $SESSION_['s_id'] = $username;
  17. }
  18. else
  19. {
  20. echo ("Access denied. <a href='login.php'>Try again?</a>");
  21. exit();
  22. }
  23. mysqli_close($dbc);
  24. }
  25.  
  26. if (isset($SESSION_['s_id']))
  27. {
  28. $dbc = mysqli_connect('127.0.0.1', '40076509', 'password', '40076509_news') or die('Error connecting to MySQL server');
  29. // Read articles from database
  30. $result = mysqli_query($dbc, "SELECT category, title, date, id FROM content") or die('Error querying the content database');
  31.  
  32. if (mysqli_num_rows($result) == 0)
  33. {
  34. echo ("No articles found");
  35. }
  36. else
  37. {
  38. while ($row = mysqli_fetch_assoc($result))
  39. {
  40. echo ("
  41. <hr><p><a href=article.php?id=" . $row["id"] . " target='_blank'>" . $row["category"] . " - " . $row["title"] . "</a>
  42. <br />" . $row["date"] . "
  43. <br /><form action='modify.php?id=" . $row["id"] . "' method='post'><input type='submit' name='submit' value='Delete' /></form></p>
  44. ");
  45. }
  46. echo ("<hr><p><a href='cmsadd.php'><button>Add New Article</button></a></p>");
  47. }
  48.  
  49. mysqli_close($dbc);
  50. }
  51. else
  52. {
  53. header("Location: login.php");
  54. exit();
  55. }
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement