PHP page access logging

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JDJones

    PHP page access logging

    I help out with a local non-profit agency's web site. They are running
    on donated web space so they don't have control over the server. About
    the only thing of use that is available to them is PHP 4.3.2. There is
    no access to the system logs and there is no database installed.

    They are asking to have a password protected page of information put up
    that is compiled from a submitted form.

    I can handle the coding to write the submitted info to a flat file and
    to read it and print it to the web page as well as setting up the
    htaccess for the password protection. But what I'm at a loss for is how
    (or even whether) I can generate a list for them using PHP of who
    actually logs into this web page to view it.

    Is there a premade script or a way I can have PHP handle this? Any
    suggestions? Thanks.

  • Zaphod Beeblebrox

    #2
    Re: PHP page access logging

    JDJones <seebelow@spryn et.com> wrote in message
    news:sNYRb.1376 42$nt4.604448@a ttbi_s51...[color=blue]
    > I help out with a local non-profit agency's web site. They are running
    > on donated web space so they don't have control over the server. About
    > the only thing of use that is available to them is PHP 4.3.2. There is
    > no access to the system logs and there is no database installed.
    >
    > They are asking to have a password protected page of information put up
    > that is compiled from a submitted form.
    >
    > I can handle the coding to write the submitted info to a flat file and
    > to read it and print it to the web page as well as setting up the
    > htaccess for the password protection. But what I'm at a loss for is how
    > (or even whether) I can generate a list for them using PHP of who
    > actually logs into this web page to view it.
    >
    > Is there a premade script or a way I can have PHP handle this? Any
    > suggestions? Thanks.
    >[/color]
    You haven't stated exactly what data you want to log here. Do you just want
    to log the usernames of those viewing the page, or do you want to store
    their ip addresses, or what? Whichever it turns out to be, if you know how
    to access a flat file for reading and writing, you have the tools at your
    disposal to create a log of this information. If, on the other hand, you
    want to log unsuccessful login attempts via the .htaccess file, you are out
    of luck. That's stored in the server logs and not available to your php
    pages, since you php pages are being protected from access.


    Comment

    • Jari

      #3
      Re: PHP page access logging

      How about this.. just made and tested it..
      It logs below information to log.txt:
      * ip
      * time
      * current page

      add this to all php pages you want to get logged

      <?php
      $curFile = $_SERVER['PHP_SELF']; // what file is being accessed
      $ip = $REMOTE_ADDR; // visitors IP

      // writing to log file
      $filename = 'c:\log.txt';
      $fp = fopen($filename , "a"); // appending to the end
      $today = date ("F j, Y, g:i a");
      $toFile = "$ip -- $today -- $curFile\r\n";
      $write = fputs($fp, $toFile);
      fclose($fp);
      ?>




      Comment

      • Jari

        #4
        Re: PHP page access logging

        "Jari" <not@here.fi> wrote in message news:bvaluj$kv$ 1@news.cc.tut.f i...[color=blue]
        > How about this.. just made and tested it..
        > It logs below information to log.txt:
        > * ip
        > * time
        > * current page
        >
        > add this to all php pages you want to get logged
        >
        > <?php
        > $curFile = $_SERVER['PHP_SELF']; // what file is being accessed
        > $ip = $REMOTE_ADDR; // visitors IP
        >
        > // writing to log file
        > $filename = 'c:\log.txt';
        > $fp = fopen($filename , "a"); // appending to the end
        > $today = date ("F j, Y, g:i a");
        > $toFile = "$ip -- $today -- $curFile\r\n";
        > $write = fputs($fp, $toFile);
        > fclose($fp);
        > ?>[/color]


        just save that code as log.php and call it from all php files using
        include 'log.php';


        Comment

        • JDJones

          #5
          Re: PHP page access logging

          Jari wrote:
          [color=blue]
          > How about this.. just made and tested it..
          > It logs below information to log.txt:
          > * ip
          > * time
          > * current page
          >
          > add this to all php pages you want to get logged
          >
          > <?php
          > $curFile = $_SERVER['PHP_SELF']; // what file is being accessed
          > $ip = $REMOTE_ADDR; // visitors IP
          >
          > // writing to log file
          > $filename = 'c:\log.txt';
          > $fp = fopen($filename , "a"); // appending to the end
          > $today = date ("F j, Y, g:i a");
          > $toFile = "$ip -- $today -- $curFile\r\n";
          > $write = fputs($fp, $toFile);
          > fclose($fp);
          > ?>[/color]

          Thanks Jari. I get the idea now. I can add $username to the information
          being written to the file and then will have everything that they asked
          for. I appreciate you pointing me in the right direction. Thanks.

          Comment

          • Jari

            #6
            Re: PHP page access logging

            "JDJones" <seebelow@spryn et.com> wrote in message
            news:LC8Sb.1403 80$nt4.623637@a ttbi_s51...[color=blue]
            > Jari wrote:
            >[color=green]
            > > How about this.. just made and tested it..
            > > It logs below information to log.txt:
            > > * ip
            > > * time
            > > * current page
            > >
            > > add this to all php pages you want to get logged
            > >
            > > <?php
            > > $curFile = $_SERVER['PHP_SELF']; // what file is being accessed
            > > $ip = $REMOTE_ADDR; // visitors IP
            > >
            > > // writing to log file
            > > $filename = 'c:\log.txt';
            > > $fp = fopen($filename , "a"); // appending to the end
            > > $today = date ("F j, Y, g:i a");
            > > $toFile = "$ip -- $today -- $curFile\r\n";
            > > $write = fputs($fp, $toFile);
            > > fclose($fp);
            > > ?>[/color]
            >
            > Thanks Jari. I get the idea now. I can add $username to the information
            > being written to the file and then will have everything that they asked
            > for. I appreciate you pointing me in the right direction. Thanks.[/color]


            no problem mate ;D


            Comment

            Working...