473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.

Jul 17 '05 #1
5 3374
JDJones <se******@sprynet.com> wrote in message
news:sNYRb.137642$nt4.604448@attbi_s51...
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.

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.
Jul 17 '05 #2
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);
?>


Jul 17 '05 #3
"Jari" <no*@here.fi> wrote in message news:bv*********@news.cc.tut.fi...
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);
?>

just save that code as log.php and call it from all php files using
include 'log.php';
Jul 17 '05 #4
Jari wrote:
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);
?>


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.

Jul 17 '05 #5
"JDJones" <se******@sprynet.com> wrote in message
news:LC8Sb.140380$nt4.623637@attbi_s51...
Jari wrote:
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);
?>


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.

no problem mate ;D
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I...
0
by: Robert Chapman | last post by:
I run into a strange problem today while enableding ODBC SQL logging on my IIS Server. Once the logging was enabled, and working fine, my two ASP.Net Applications could no longer connect to the...
7
by: guy | last post by:
I have an htm page which is often visted and it's a very established page and for that reason I cannot change its extension to asp. However, I want to run a bit of VB code on the server whenever...
7
by: Jean-David Beyer | last post by:
I have six hard drives (4 SCSI and 2 EIDE) on my main machine with parts of a database on each drive. The main index is on one SCSI drive all to itself. The main data are on the other three SCSI...
6
by: omyek | last post by:
I'm trying to mimic the browsing of a webpage using an HttpWebRequest. I've had a lot of luck with it so far, including logging into pages, posting form data, and even collecting and using cookies....
7
by: Alan Silver | last post by:
Hello, Sorry this is a bit wordy, but it's a pretty simple question... I have a web site, http://domain/ which is a public site, part of which (http://domain/a/) is protected by forms...
0
by: Shane | last post by:
Does anyone have any advise on how I can fix the error message shown below? Thanks in advance for any ideas, Shane Server Error in '/' Application....
4
by: Alfa & Omega | last post by:
I should access page which requires authorization... Now, I'm using .net c#... and would like to know how to do that logging on that kind of page? Thanks all and sorry for my English! ;) BR...
1
by: Chris108 | last post by:
Hello to all, I am a self starter in network administration - last year accomplished A+ certification. No job yet but in my spare time I am developing my own network with several laptops. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.