Solved

please help in simple php file

Posted on 2011-03-08
4
313 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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).

839 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