Solved

please help in simple php file

Posted on 2011-03-08
4
321 Views
Last Modified: 2013-12-25
Hello experts.
Please help me.
I need to create a php file  that if is open it logs the date,time and remote ip that opened it.
File need to save this stats into a text file.
Please help me with this.
And the last, tell me how to use it in other files.
Example  : i have a index.php file that contains many other instructions.
How to include this into index.php look alike this method : include_once.. or other...
please help.
thanks
0
Comment
Question by:helyonprime96
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 35073584
The best way to proceed is to write a small file like so

UNTESTED CODE

$fp = fopen("/path/to/log/file.txt', 'a' );
fprintf( $fp, "%s %s\n", strip_tag( $_SERVER['REMOTE_ADDR'] ), date("Y-m-d H:i:s") );
fclose($fp);

and put that in a php file - say logger.php - and then include this wherever you need it

---- index.php starts
<?php
   include 'logger.php';

   ..... your code
?>
---- index.php ends

0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 500 total points
ID: 35073595
0
 

Author Comment

by:helyonprime96
ID: 35080031
thanks. i will test it
0
 

Author Closing Comment

by:helyonprime96
ID: 35361739
thanks
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question