Ok,I finished it
It's four files.
connect.php
<?php
//Time Diff Config
$con = mysql_connect("localhost", "DB USERNAME", "DB PASSWORD") or die(mysql_error());
mysql_select_db("name of DB") or die(mysql_error());
$hours= 8;//Hour diff between your webserver and your PC.Check in hourdiff.php
$negorpos= "+";//If number has a - sign next to it then change "+" to "-"
ipstoring.php
<?php
/**
* @author kostis
* @copyright 2009
*/
include ('connect.php');//connecting To the DB
$ip = $_SERVER['REMOTE_ADDR']; //Getting the visitor's ip'
$visittimesec=date('H')*3600 + date('i')*60 + date('s') ;//server time in seconds
$timediffsec=$hours*3600;//Replace 8 by the hour dif between your server and your Computer,If your PC and your Server have the same time comment out this and the other lines I've marked and uncomment the one marked as "Uncomment if PC time=Server time"
if ($negorpos == "+")
{
$localtimesec=$visittimesec + $timediffsec;//Comment if PC time
}
elseif ($negorpos == "-")
{
$localtimesec=$visittimesec - $timediffsec;//Comment if PC time
}
else
{
echo "Wrong symbol,you can only imput \"-\" or \"+\"";
}
// Creditgoes to Neil Wattam for creating the script below.
$inputval = $localtimesec; //
//$inputval = $visittimesec; //Uncomment if PC time=Server time
$unith =3600; // Num of seconds in an Hour...
$unitm =60; // Num of seconds in a min...
$hh = intval($inputval / $unith); // '/' given value by num sec in hour... output = HOURS
$ss_remaining = ($inputval - ($hh * 3600)); // '*' number of hours by seconds, then '-' from given value... output = REMAINING seconds
$mm = intval($ss_remaining / $unitm); // take remaining sec and devide by sec in a min... output = MINS
$ss = ($ss_remaining - ($mm * 60)); // '*' number of mins by seconds, then '-' from remaining sec... output = REMAINING seconds.
//end of Neil Wattam's Script.Thanks a lot for helping me.'
$visittime = "".$hh.":".$mm.":".$ss;
//Inserting in the DB
$get="INSERT INTO visitors (ip ,visittime) VALUES ('$ip','$visittime')";
if (!mysql_query($get,$con))
{
die('Error: ' . mysql_error());
}
?>
dataemailing.php
<?php
include("connect.php");
function display_db_query($query_string, $connection, $header_bool, $table_params) {
// perform the database query
$result_id = mysql_query($query_string, $connection)
or die("display_db_query:" . mysql_error());
// find out the number of columns in result
$column_count = mysql_num_fields($result_id)
or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// optionally print a bold header at top of table
if($header_bool) {
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
print("<TH>$field_name</TH>");
}
print("</TR>\n");
}
// print the body of the table
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
print("<TD>$row[$column_num]</TD>\n");
}
print("</TR>\n");
}
print("</TABLE>\n");
}
function display_db_table($tablename, $connection, $header_bool, $table_params) {
$query_string = "SELECT * FROM $tablename";
display_db_query($query_string, $connection,
$header_bool, $table_params);
}
?>
<?php
$table = "visitors";
//define the receiver of the email
$to = 'receiver@email.com';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: text/html;";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
<html>
<?php display_db_table($table, $con,TRUE, "border='2'"); ?>
</html>
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
mysql_query("DELETE FROM visitors") or die(mysql_error());
?>
</TD></TR></TABLE></BODY></HTML>
hourdiff.php
<?php
/**
* @author Constantine Loukas
* @copyright 2009
*/
if ($diff!='yes')
{
?>
<html>
<body>
<center>
<?php echo date('H'); ?>
<form action="hourdiff.php?diff=yes" method="post">
Your computer's time(Just Hours) <input type=text name="hour"><br />
<input type="submit" value="Go!">
</center>
</form>
<?php
}
elseif ($diff=='yes')
{
$servertime=date('H');
if ($_POST[hour] < $servertime)
{
echo "Time Diff -";
echo $servertime - $_POST[hour];
}
elseif ($_POST[hour] == $servertime)
{
echo "Server time=Pc time.Please comment out the lines marked in ipstore.php";
}
elseif ($_POST[hour] > $servertime)
{
echo "Time Diff ";
echo $_POST[hour] - $servertime;
}
}
else
{
echo "Error in the form";
}
?>
Table Structure
CREATE TABLE IF NOT EXISTS `visitors` (
`ip` varchar(25) CHARACTER SET latin1 NOT NULL,
`visittime` varchar(255) CHARACTER SET latin1 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
It's important that the filenames are exactly as I've written them.
If you want I can upload the files.
To make it work just include ipstoring.php in any file that you want.