Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*----------- connection.class.php -----------*/
- // Begins a session
- session_start();
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- }catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $timeTillLock = 3600;
- // SESSION expires after 60 minutes
- 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)){
- // Request 30 minutes ago
- $_SESSION["locked"] = "Locking";
- }
- if(isSet($_SESSION["locked"]) && $_SESSION["locked"] == "Locking"){
- // Sends you back to the login page
- header("Location: lock.php");
- $_SESSION["locked"] = "Locked";
- }
- // Sets your last activity to current time ( Resets if you revisit a page or submit a form )
- $_SESSION['LAST_ACTIVITY'] = time();
- function insert_act($user_id, $activity, $action){
- // Defines the Database info, change info to the websites database info before committing
- $dsn = 'mysql:dbname=celery;host=localhost';
- $user = 'root';
- $pass = '';
- // Creates a connection to the database with database info defined above
- try {
- $connection = new PDO($dsn, $user, $pass);
- $connection->query("SET NAMES utf8");
- }catch (PDOException $exception) {
- echo $exception;
- echo "Failed to connect to database";
- }
- $getMaster = $connection->prepare("
- SELECT user_main
- FROM users
- WHERE user_id=$user_id
- ");
- if($getMaster->execute()){
- if($getMaster->rowCount() > 0){
- while($row = $getMaster->fetch()){
- $master_id = $row["user_main"];
- }
- if($master_id == -1){
- $master_id = $user_id;
- }
- $time = date("Y-m-d H:i:s");
- $insAct = $connection->prepare("
- INSERT INTO log
- (user_id, master_id, activity, action, timestamp)
- VALUES (:id, :mId, :activity, :action, :time)
- ");
- $insAct->bindValue(":id", $user_id, PDO::PARAM_STR);
- $insAct->bindValue(":mId", $master_id, PDO::PARAM_STR);
- $insAct->bindValue(":activity", $activity, PDO::PARAM_STR);
- $insAct->bindValue(":action", $action, PDO::PARAM_STR);
- $insAct->bindValue(":time", $time, PDO::PARAM_STR);
- if($insAct->execute()){
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement