Track whos accessing reports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Neekos
    New Member
    • Aug 2007
    • 111

    Track whos accessing reports

    I have an internal web page for my company that has a list of hyperlinks so that users can access different reports (.xls files on the server). What i would like to do is to keep track of who is accessing each report in a database.

    I attempted to use the OnClick property of the <a href> tag to send a SQL query to insert the data into the table, however that wasnt working. Upon further investigation on the web - it appears the OnClick property only handles javascript or vbscripts.

    Does anyone have any ideas on how i can go about accomplishing this?

    Thank you in advance.
  • Neekos
    New Member
    • Aug 2007
    • 111

    #2
    I forgot to add - the users are hitting a login screen before they get to the reports page, so im gathering their login data through that.

    also - the table im trying to populate has the following metadata:

    user - varchar(6)
    date - timestamp
    report_name - varchar(150)

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Neekos.

      The easiest way to do this is to review your server access log.

      A slightly more sophisticated method would be to provide access to these files via a PHP script:

      [code=php]
      /* Verify credentials. */
      if( empty($_SESSION['isLoggedIn']) )
      {
      goToLoginScreen ();
      }

      /* Verify that file exists. */
      if( $filePath = getFilePathFrom FileID($_GET['fileid']) )
      {
      /* Log file access. */
      recordFileAcces sToLogFile($_GE T['fileid'], $_SESSION['userid']);

      /* Send the file to the browser. */
      header('Content-Type: application/force-download');
      header('Content-Disposition: attachment');
      header('Content-Length: ' . filesize($fileP ath));

      readfile($fileP ath);
      }
      [/code]

      Comment

      • Neekos
        New Member
        • Aug 2007
        • 111

        #4
        ok - i understand the verify the login creds and to verify the file exists...thats all in place.

        I'm not understanding this line tho:

        Code:
        recordFileAccessToLogFile($_GET['fileid'], $_SESSION['userid']);
        what is that doing? and where is the recordFileAcces sToLogFile function?

        thanks for your reply!

        Comment

        • Neekos
          New Member
          • Aug 2007
          • 111

          #5
          also - these are hyperlinks they are clicking to view the files. Here is a an example of part of the table:

          Code:
          <TD><a href="Static_Linked_Reports/WCT_HG.xls">WCT Hotel Guides CRD</a></TD>
          <TD><?php
          $filename = "Static_Linked_Reports/WCT_HG.xls";
          echo date ("F d Y H:i", filemtime($filename))
          ?></TD>

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            I used "recordFileAcce ssToLogFile" as a dummy function name. This would be the function where you record that the User accessed the file.

            Going back to your OP, I see that you are recording the access log info in a database, so a better name for the function might be recordFileAcces sToDatabase() (or you can just inline the SQL query and not bother with outsourcing it to an external function).

            Comment

            • Neekos
              New Member
              • Aug 2007
              • 111

              #7
              The part im not understanding is how to call the function (or the SQL update query) when the hyperlink is clicked.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by Neekos
                The part im not understanding is how to call the function (or the SQL update query) when the hyperlink is clicked.
                The link would point to a page, say, 'process.php'. Then in process.php, you would do what PBMods said above.

                Comment

                Working...