Go Back   Pictual Design Forums > Graphics > Tutorials
Top Posters Referers Register Members List Calendar Search Today's Posts Mark Forums Read

Tutorials Staged guides related to design, graphics and skinning.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-13-2005, 02:33 PM
FireNova FireNova is offline
Returning Member
Elite Member (500+ posts)
 
Location: Uk
Rep Power: 0
FireNova is an unknown quantity at this point
Send a message via MSN to FireNova
Default

Do you want to log the details of visitors to your site? Here is a basic tutorial on making a php logger which will log details of users visiting your site.

1.) Open the file you want to put the logger in(best to be the pages the visitors are visiting)

Add if a .html or htm
Code:
<?php $file = fopen("log.html", "a"); flock($file, LOCK_EX); $time = date("H:i dS F"); fwrite( $file, "<b>Time:</b> $time<br/>" ); if( $REMOTE_ADDR != null) { fwrite( $file, "<b>IP Address:</b> $REMOTE_ADDR <br/>"); } if( $HTTP_REFERER != null) { fwrite( $file, "<b>Referer:</b> $HTTP_REFERER<br/>"); } fwrite( $file, "<b>Browser:</b> $HTTP_USER_AGENT<br/></br>"); flock($file, LOCK_UN); fclose($file); ?>

If the file is a .php file and already is in php just remove the <?php and ?> in the code above

2.)Now make a log.html file that is blank

Explantation of the code
Code:
$file = fopen("log.html", "a");

$file is given the command to open log.html

Code:
flock($file, LOCK_EX);

To acquire the exclusive lock (writer)

Code:
$time = date("H:i dS F"); fwrite( $file, "<b>Time:</b> $time<br/>" );

$time is given the value of the server time with the time format
fwrite now uses $file which was seen before to write Time in bold with the time using $time.
Code:
if( $REMOTE_ADDR != null) { fwrite( $file, "<b>IP Address:</b> $REMOTE_ADDR <br/>"); }

Now the code checks if $REMOTE_ADDR is true(existent) if $remote_addr is true it goes to fwrite where it uses $file again then with ip address in bold and then the users $REMOTE_ADDR
Code:
if( $HTTP_REFERER != null) { fwrite( $file, "<b>Referer:</b> $HTTP_REFERER<br/>"); }

If $HTTP_REFERER is true then fwrite using $file with Referer in bold with the $HTTP_REFERER which is where the person came from(website or page) If the person typed in the address into their address bar then REFERER will appear
Code:
fwrite( $file, "<b>Browser:</b> $HTTP_USER_AGENT<br/></br>");

The final piece of fwrite, it uses the $file line again this time with Browser in bold and then $HTTP_USER_AGENT which gets the person's browser type.

example:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; .NET CLR 1.0.3705)
Opera/6.0 (Windows XP; U) [en]
Code:
flock($file, LOCK_UN);

To release the lock (shared or exclusive)

Code:
fclose($file);

Its time to fclose the $file which closes log.html

Hopefully you read the expantation instead of just copy and pasting

I hope you enjoyed my tutorial.

CheetahShrk
Reply With Quote
  #2  
Old 12-17-2005, 05:40 AM
wysek wysek is offline
Returning Member
 
Rep Power: 0
wysek is off the scale
Default

great this is a very very super
Reply With Quote
  #3  
Old 03-05-2006, 11:00 AM
dom1n1k dom1n1k is offline
Returning Member
 
Rep Power: 0
dom1n1k is off the scale
Default

wow its nice tutrial need to test this code on my page but THNAKS
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php links xplicit Programming 4 08-30-2006 04:09 PM
PHP Arrays ownsyou Tutorials 4 03-05-2006 11:03 AM
Introduction to Php dbfootballa3 Tutorials 11 12-01-2005 11:33 AM
Php Simple Email Script FireNova Tutorials 4 07-01-2005 07:56 PM
Php Randomizing images FireNova Tutorials 3 06-19-2005 04:00 PM


All times are GMT -4. The time now is 04:34 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.