# [SOLVED] HTML to log ip address?



## Mattman86

Is there any way to make my web page log in a text file the ip address of my visitors?


----------



## dm01

*Re: HTML to log ip address?*

Yes, there is. Why do you want to do this?


----------



## Mattman86

*Re: HTML to log ip address?*

I am wanting to be able to track the amount of of new visitors for a period of time and see what the general area of the world they are in.


----------



## Jaxo

*Re: HTML to log ip address?*

http://www.google.com/analytics/

A great resource for getting information about traffic coming to your site. Even better is that it's free!


----------



## Mattman86

*Re: HTML to log ip address?*

Are there any other ways?


----------



## Ferimer5

*Re: HTML to log ip address?*

Yes, via PHP. Then use the script as javascript on an html page.

place in the html page and edit the location of the php file to the location youll create: 



Code:


<script language="JavaScript type="text/javascript" src=http://YOURSITE.COM/log.php"></script>
<script type="text/javascript" src="http://javascripthost.com/scripts/logupdate.js"></script>

log.php :


Code:


<?php
$logfile= 'info.html';
$IP = $_SERVER['REMOTE_ADDR'];
$logdetails=  date("F j, Y, g:i a") . ': ' . '<a target=_blank href=http://www.dnsstuff.com/tools/ipall.ch?domain='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>';
$rc = fopen($logfile, "a"); 
fwrite($rc, $logdetails);
fwrite($rc, "<br />_____ Provided by JavaScripthost.com _____");
fwrite($rc, "<br>");
fclose($rc); 
?>


----------



## sobeit

*Re: HTML to log ip address?*

check your vdeck or cpanel and see if the logs are there. most hosting services provides logs as part of your sites control panel


----------



## Mattman86

*Re: HTML to log ip address?*

Hey, thanks guys. I'll refer my friends to this forum when they need help.


----------



## evilbudz

Mattman86 said:


> Is there any way to make my web page log in a text file the ip address of my visitors?


here is my little script to log ip addresses
dont forget to add the below after the /HEAD tag
also note to make this work it must be a PHP not HTML

<?php include ('log-ip.php') ?>

where ever you want it called from

"log-ip.php"

<?php
$iplogfile = 'logs/ip-address-mainsite.html';
$ipaddress = $_SERVER['REMOTE_ADDR'];
$webpage = $_SERVER['SCRIPT_NAME'];
$timestamp = date('d/m/Y h:i:s');
$browser = $_SERVER['HTTP_USER_AGENT'];
$fp = fopen($iplogfile, 'a+');
chmod($iplogfile, 0777);
fwrite($fp, '['.$timestamp.']: '.$ipaddress.' '.$webpage.' '.$browser. "\n<br><br>");
fclose($fp);
?>

and the result is a nice web HTML log file
logs/ip-address-mainsite.html

<!DOCTYPE html><!-- HTML5 -->

<head>
<body bgcolor="#000000">
<title>NZ Quakes - Main Web Site Log</title>

</head>

<body>
<font color="#7FFF00">
<center>NZ Quakes - Main Web Site Log</center>
<font color="gold">
<br><center>
[01/04/2017 08:25:21]: 124.197.9.181 /index.php Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36
<br><br>

below is a picture of what it looks like.

what do you think about this i think its clean and simple sort of.

[1]: https://i.stack.imgur.com/8D0Ea.png


----------



## brent.charlebois

You also might want to store your info in a database such as MySql.


----------

