Hi,

I am looking for a php script to track the visitors ip address with the time and the date of the visit and sending email to my email address everyday.

I am already using a php script but it send the email for every single visit of the customer. But I want the email to be sent once in a day with all the details.

If any one can help with the php script appreciated.

Please see below for the php script I am using if you can modify it to able to use as I expected would be appreciated.

<?php

$to = 'name@name.com'; // The email address you want notifications sent to
$subject = 'Visitors IP'; // What do you want the subject line of notifications to be?

// published at: scripts.tropicalpcsolutions.com

$visitorSpecs =
"<hr size=2 width=300 align=left>".
"<b>Visitor IP address:</b> ".$_SERVER['REMOTE_ADDR'];

$headers = "Content-type: text/html \nFrom: IP sniffer script";

$body = "<body>
<br>

Thank you

    you could try saving the IPs or any other info in a table in MYSQL and then using CRON a script could retrieve the data from the DB,emai it to you and deleting the entries from the DB.
    I'm not sure how exactly you can do that though.I'll try to do it but I'm sure that more experienced coders will have other and better solutions.

      Hi,

      Thank you for the advice.

      I really don't have much knowledge about php and my sql. But My server have both faciliites installed. So if some one be able to offer their help that would be appreciated.

        I'm almost finished with inserting them to the DB but I'll need some help with the E-mail part.I'll finish it tomorrow.

          Hi,

          Thank you for the kind help.

          I am looking forward to see that tomorrow.

          Regards

            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.

              Hi,

              I have done everything but on the page I added the code show the display as

              Parse error: parse error in D:\heathrowtaxis.info\wwwroot\connect.php on line 4

              What can I do to correct this.

              Regards

                Hi,can you please post the file in which you are including ipstoring.php ?

                  Hi,

                  Thank you for the excellent work

                  I forgot to enter the database name and that is corrected now.

                  I can see the ip records are on the database and when will I receive the email. How can I change the time limit to receive the email.

                  One more thing I do live in UK but the ip records on the database are recording on a different time zone how can I change that to make it record on UK time.

                  Thank you

                    To change the timezone just point your browser to timediff.php and enter the hour in the UK in the box,click submit and write down the number that appears.If it's a negative note that too.then open config.php and change
                    $hours= 8;//Here enter the number without the "-" if it's negative
                    $negorpos= "+";//if the number is negative change this to "-"

                    To set the mail to be automatically sent to your email account you need to set a CRON job.Go to your website's control panel and click CRON jobs.after setting the time you need to add to the command box :
                    /home/(username)/public_html/(pathto)/dataemailing.
                    scriptname
                    change the words in () according to your details.
                    (username) is your account username with your hosting company
                    (pathto) is the path to the folder in which dataemailing.php is.

                    If you need anything else just tell me

                      6 days later

                      Since I haven't heard from you for some time I think that the script works fine so please mark this thread as resolved

                        Write a Reply...