Good IP Logger?

Whats a good IP logger for the free services of 000webhost. If you have any please tell me how to install them onto it. Because I have tried like 3 and none work right.

Fun little code snippet:


<?php
@$fp = fopen("ip_log.txt", "ab");
if(!$fp) {
echo "Could not open file for logging";
}
else {
$str = $_SERVER["REMOTE_ADDR"];
$str .= " ";
$str .= date("H:i, d M Y");
fwrite($fp, $str);
fclose($fp);
}
?>

Problem with the script above is that txt files are blocked on 000webhost…

Not via FTP or PHP script (i.e. local access)

and you can name it anything u want… log.dat example

How do you retrieve the data?:confused:

On your site upload a file (open notepad save a blank document as logfile.html set as all files) to your root.

<?php
@$fp = fopen("logfile.html", "ab");
if(!$fp) {
echo "Could not open file for logging";
}
else {
$str = $_SERVER["REMOTE_ADDR"];
$str .= " ";
$str .= date("H:i, d M Y");
fwrite($fp, $str);
fclose($fp);
}
?> 

Use the code and after visiting the page with this code - go to yourwebsite.com/logfile.html and view it.

If it doesn’t work then chmod your directory and files to 777

Thanks James! :slight_smile:

you could also make it really easy and use some kind of counter.
Here is one : http://stats.rdproducktions.com (it logs ip’s and does more, too)
plus to retrieve the information you use an easy web interface

Thanks RDP! I have installed it. Now if I can just generate some traffic so I can make some cash to donate… :slight_smile:

im coding an statics script, well most of the work is done, and its working allready. now styling needed and backend so you can easily choose what data you want to show to your website users. i will add more functions once i have time and im on mood to code :slight_smile:

if you got any ideas/suggestions, let me know. im looking to make this script puplic.

this is how it looks like now. my website stats

anyway, this is what u was looking for actually so i just post this now, and the complete script once its ready.

iplogger.php

<?php

////get all the info

//ip address
$_ip = $_SERVER['REMOTE_ADDR'];
//end

//host
$_host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
//end

//browser
$_browser = $_SERVER['HTTP_USER_AGENT'];
//end

//date
$_date = date("r");
//end

////all data have been collected now then we

////make a string to write into file
$_contents = $_ip . "~" . $_host . "~" . $_browser . "~" . $_date . "&";
////end

////enter info into file
$_filename = "logs.txt";
$_handle = fopen($_filename, 'a');
////if the file doesnt exist, script create it and chmod it 777 so we can write on it
@chmod("logs.txt", 0777);
@fwrite($_handle, $_contents);
fclose($_handle);
////end


?>

stats.php


<?php

////open the log file

$_filename = "logs.txt";
$_handle = fopen($_filename, "r");
$_contents = fread($_handle, filesize($_filename));
fclose($_handle);

////end


////divide all the ip address
$_divide = explode("&", $_contents);
////end

////get info out of the divide
$_array = 0;
echo "<div align='left'";
while($_divide[$_array] != '')
{

////make a list
list($_ip, $_host, $_browser, $_date) = explode("~", $_divide[$_array]);
////end

////print out the data
echo "<br>";
echo "<b>IP: </b>" . $_ip . "<br>";
echo "<b>Host: </b>".$_host . "<br>";
echo "<b>Browser: </b>".$_browser . "<br>";
echo "<b>Date: </b>".$_date . "<p>";
////end

$_array++;
}
echo "</div>";
////end

?>

Now we have 2 php scripts. how to use them?

1.CHMOD the permissions on the logs.txt to 0777.
2.To log your visitors enter this code:

<?php
include(“iplogger.php”);
?>

ps. you should protect the stats.php file, since there are full ip addresses. and other info, so only site admin/moderators should see it. just advice :rolleyes:

How to protect file stats.php?

protector.php

<?php
/**
 * ****************************************************************************
 * 
 * USAGE:
 *   Define your requested password below and inset the following code
 *   at the beginning of your page you dont want others to access.
 *   
 *   <?php require_once("protector.php"); ?>
 * 
 * 
 * 
 ''***********************************************************************************/


$Password = 'your_secret_password'; // Set your password here

   if (isset($_POST['submit_pwd'])){
      $pass = isset($_POST['passwd']) ? $_POST['passwd'] : '';
      
      if ($pass != $Password) {
         showForm("Wrong password");
         exit();     
      }
   } else {
      showForm();
      exit();
   }
   
function showForm($error="LOGIN"){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>This is protected page - login</title>
   <style>
#main {
    margin: auto;
	border: 1px solid #cccccc;
	width: 300px;
	background: #F1F3F5;
    font-family: Arial, Helvetica, sans-serif;
    font-weight:bold;
    font-size : 12px;
}

form {
    margin-left: 100px;
	border: 1px solid #cccccc;
	width: 160px;
	background: #E9ECEF;
    font-family: Arial, Helvetica, sans-serif;
    font-weight:bold;
    font-size : 12px;
    padding:5px;
    margin-bottom:10px;
}

#result {
    margin-left: 100px;
	border: 1px solid #cccccc;
	width: 160px;
	background: #E9ECEF;
    font-family: Arial, Helvetica, sans-serif;
    font-weight:bold;
    font-size : 12px;
    padding:5px;
    margin-bottom:50px;
}

.text {
	border: 1px solid #cccccc;
}

input {
    border: 0px solid #cccccc;
}

.values{
  font-family: verdana;
  font-weight:normal;
  font-size : 10px;
  align:top;
  vertical-align:top;
}

.key{
  font-family: verdana;
  font-weight:bold;
  font-size : 12px;
  padding-bottom:15px;
}


.caption{
    font-family: Arial, Helvetica, sans-serif;
    font-weight:bold;
    margin:10px;
    font-size : 14px;
    color:#C64934;
}

#icon{
    width:100px;
    height:100px;
    float:left;
    background-image:url(icon.gif);
    background-repeat: no-repeat;
    background-position:center center;
}
#icon2{
    width:100px;
    height:100px;
    float:left;
    background-image:url(icon2.gif);
    background-repeat: no-repeat;
    background-position:center center;
}

#source{
  text-align:right;
  align:right;
  padding-right:10px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight:normal;
  font-size : 10px;
  color:#CCCCCC;
}
</style>
</head>
<body>
    <div id="main">
      <div class="caption"><?php echo $error; ?></div>
      <div id="icon">&nbsp;</div>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="pwd">
        Password:
        <table>
          <tr><td><input class="text" name="passwd" type="password"/></td></tr>
          <tr><td align="center"><br/>
             <input class="text" type="submit" name="submit_pwd" value="Login"/>
          </td></tr>
        </table>  
      </form>
   </div>
</body>       

<?php   
}
?>

stats.php

<?php

////open the log file

$_filename = "logs.txt";
$_handle = fopen($_filename, "r");
$_contents = fread($_handle, filesize($_filename));
fclose($_handle);

////end


////divide all the ip address
$_divide = explode("&", $_contents);
////end

////get info out of the divide
$_array = 0;
echo "<div align='left'";
while($_divide[$_array] != '')
{

////make a list
list($_ip, $_host, $_browser, $_date) = explode("~", $_divide[$_array]);
////end

////print out the data
echo "<br>";
echo "<b>IP: </b>" . $_ip . "<br>";
echo "<b>Host: </b>".$_host . "<br>";
echo "<b>Browser: </b>".$_browser . "<br>";
echo "<b>Date: </b>".$_date . "<p>";
////end

$_array++;
}
echo "</div>";
////end

?> 

I use this method and works well since nobody can see the password inside the protector.php