store and retrieve sessions

Posted in CategoryGeneral Discussion
  • Terry Ogbemudia 1 year ago

    Great job!!!

  • Will 1 year ago

    i just added a update Set to the top of my header and its updating now

  • Terry Ogbemudia 1 year ago

    You want to track any visitor or only logged in users?

     

  • Will 1 year ago

    hey terry it updates all users but this also requires login or cookie so if they are not going through the user login process then it will never update until they use the login again

  • Will 1 year ago

    I did it still updates everyones last activity

      $db = dbconnect();       
            $stmt = $db->prepare("UPDATE users SET DateLastVisit = ? WHERE ID = ?");
            $stmt->bind_param('ss', $Date, $_SESSION['ID']);
            $stmt->execute();
            $result = $stmt->get_result();
            $stmt->close();

  • Terry Ogbemudia 1 year ago

    Add a Where clause to the query

  • Will 1 year ago

    I di the following terry but it updates all users last activity field at the same time

     

    function guard(){
       
        $Date = date('Y-m-d H:i:s');
       
        $IsValid = true;
        $InActive = 60 * 15; //15 mins
        $fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
       
        if((isset($_SESSION['fingerprint']) && $_SESSION['fingerprint'] != $fingerprint)){
            $IsValid = false;
            Signout();
        }else if((isset($_SESSION['last_active']) && (time() - $_SESSION['last_active']) > $InActive) && $_SESSION['Name']){
            $IsValid = false;
            Signout();
        }else{
            $_SESSION['last_active'] = time();
           
            $db = dbconnect();       
            $stmt = $db->prepare("UPDATE users SET DateLastVisit = ?");
            $stmt->bind_param('s', $Date);
            $stmt->execute();
            $result = $stmt->get_result();
            $stmt->close();       
           
        }
       
        return $IsValid;
    }

  • Terry Ogbemudia 1 year ago

    I will look into it, I don't have an already made script but it shouldn't be that difficult to implement.

  • Will 1 year ago

    can you maybe provide an example? I did one on the login but it only works if they login everytime

  • Terry Ogbemudia 1 year ago

    You can add sql query to the guard function we created in the login course, log the users id then update active time in the database whenever the user make any request.

Please login or register to leave a response.