Advertisement
Guest User

Untitled

a guest
May 15th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. <?php
  2. /*----------- connection.class.php -----------*/
  3.  
  4. // Begins a session
  5. session_start();
  6.  
  7. // Defines the Database info, change info to the websites database info before committing
  8. $dsn = 'mysql:dbname=celery;host=localhost';
  9. $user = 'root';
  10. $pass = '';
  11.  
  12. // Creates a connection to the database with database info defined above
  13. try {
  14. $connection = new PDO($dsn, $user, $pass);
  15. $connection->query("SET NAMES utf8");
  16. }catch (PDOException $exception) {
  17. echo $exception;
  18. echo "Failed to connect to database";
  19. }
  20.  
  21. $timeTillLock = 3600;
  22.  
  23. // SESSION expires after 60 minutes
  24. if(isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > $timeTillLock) && !isSet($_SESSION["locked"]) || isSet($_SESSION["locked"]) && $_SESSION["locked"] == "" && isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > $timeTillLock)){
  25. // Request 30 minutes ago
  26. $_SESSION["locked"] = "Locking";
  27. }
  28. if(isSet($_SESSION["locked"]) && $_SESSION["locked"] == "Locking"){
  29. // Sends you back to the login page
  30. header("Location: lock.php");
  31. $_SESSION["locked"] = "Locked";
  32. }
  33. // Sets your last activity to current time ( Resets if you revisit a page or submit a form )
  34. $_SESSION['LAST_ACTIVITY'] = time();
  35.  
  36. function insert_act($user_id, $activity, $action){
  37. // Defines the Database info, change info to the websites database info before committing
  38. $dsn = 'mysql:dbname=celery;host=localhost';
  39. $user = 'root';
  40. $pass = '';
  41.  
  42. // Creates a connection to the database with database info defined above
  43. try {
  44. $connection = new PDO($dsn, $user, $pass);
  45. $connection->query("SET NAMES utf8");
  46. }catch (PDOException $exception) {
  47. echo $exception;
  48. echo "Failed to connect to database";
  49. }
  50.  
  51. $getMaster = $connection->prepare("
  52. SELECT user_main
  53. FROM users
  54. WHERE user_id=$user_id
  55. ");
  56.  
  57. if($getMaster->execute()){
  58. if($getMaster->rowCount() > 0){
  59. while($row = $getMaster->fetch()){
  60. $master_id = $row["user_main"];
  61. }
  62.  
  63. if($master_id == -1){
  64. $master_id = $user_id;
  65. }
  66.  
  67. $time = date("Y-m-d H:i:s");
  68.  
  69. $insAct = $connection->prepare("
  70. INSERT INTO log
  71. (user_id, master_id, activity, action, timestamp)
  72. VALUES (:id, :mId, :activity, :action, :time)
  73. ");
  74.  
  75. $insAct->bindValue(":id", $user_id, PDO::PARAM_STR);
  76. $insAct->bindValue(":mId", $master_id, PDO::PARAM_STR);
  77. $insAct->bindValue(":activity", $activity, PDO::PARAM_STR);
  78. $insAct->bindValue(":action", $action, PDO::PARAM_STR);
  79. $insAct->bindValue(":time", $time, PDO::PARAM_STR);
  80.  
  81. if($insAct->execute()){
  82. return true;
  83. } else {
  84. return false;
  85. }
  86. } else {
  87. return false;
  88. }
  89. } else {
  90. return false;
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement