troubleshooting Question

keep track of visitors ip address and the time they spent on my site

Avatar of neonlights
neonlights asked on
PHP
22 Comments3 Solutions356 ViewsLast Modified:
Hello,

I am trying to create a php code - that open a .txt file in my root directory and write whoever visits my site - ip address, may be location (from where.. ) and time of enter..

I do not want to use database.. I am wondering with the txt file.. and also wondering what will happen if two users trying enter my site at the same time.. about the .txt file..

Here is what I have - on top of my index.php page:

<?
session_start();
$_SESSION["currip"] = $_SERVER['REMOTE_ADDR'];
$_SESSION["timeofentry"] = date("Y-m-d h:i:s",time());
$file = 'dump.txt';
$fh = fopen($file, 'w') or die('Could not open file');
fwrite($fh, '$_SESSION["currip"]') or die('Could not write to file');
fclose($fh);
/?>

Also that my die() message - ~~ I do not want to disturb the users with my error messages. I thought that my host will have those info, but they do not.

any suggestions? Again, I am learning PHP and want to practice...

Thanks all
ASKER CERTIFIED SOLUTION
stormist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 22 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros