Go Back   Access World Forums > Apps and Windows > Web Design and Development > PHP & MySQL

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-15-2019, 08:23 PM   #1
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA
Posts: 571
Thanks: 70
Thanked 61 Times in 61 Posts
vba_php is on a distinguished road
identifying web crawlers / spiders by PHP scripting

in the attached image, i'm looking at the "who's online" page. I have a php traffic report page for a customer that, when accessed, echoes out database data that has been stored by way of another php script that captures geoLocation data (ip address of ISP, referrer page, date/time of visit) using PHP global variables.

my question is - how does this forum script know the identity of the google spiders? in my traffic report, i am only capturing the ip address of the ISP as the identifying information. from what I understand, it's not possible to capture the actual location of the visitor, only the ISP's location. if I look up the ip address on an ip lookup website, i can see that it is a google spider, but can this be done through PHP scripting?
Attached Images
File Type: jpg visitor identification.jpg (95.3 KB, 15 views)

vba_php is offline   Reply With Quote
Old 11-16-2019, 01:16 PM   #2
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA
Posts: 571
Thanks: 70
Thanked 61 Times in 61 Posts
vba_php is on a distinguished road
Re: identifying web crawlers / spiders by PHP scripting

if anyone is interested, I found the best solution (although not perfect) via other PHP websites and knowledgebases. Here is the solution:

The report page:
Code:
<?php


$dbHost = "localhost";
$dbName= "rptDatabase";
$dbUsername = "username";
$dbPassword = "password";

	$conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);

	if (mysqli_connect_errno()) {
		echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
    $sql = mysqli_query($conn, "SELECT ip
                                     , host
                                     , page 
                                     , DATE_FORMAT(date, '%m/%d/%y') as date
                                     , TIME_FORMAT(time, '%T') as time
                                FROM tblTraffic 
                                ORDER BY date DESC, time DESC");
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TRAFFIC REPORT</title>
<style type="text/css">
    table  { font-family: verdana, sans-serif; font-size: 10pt; width: 100%; border-collapse: collapse; }
    th, td { width: 20%; text-align: center; padding: 8px; }
    th     { background-color: #396; color: #FFF; }
</style>
</head>
<body>
    <table border='1'>
        <tr>
            <th>VISITOR IP ADDRESS, ISP NAME</th>
            <th>VISITOR DOMAIN ADDRESS</th>
            <th>PAGE VISITED</th>
            <th>DATE</th>
            <th>TIME</th>
        </tr>
        
        <?php
            // printing table rows
            while($row = mysqli_fetch_row($sql)) {
                echo '<tr>'; 
                foreach ($row as $key => $col) {
					echo "<td>$col</td>";
            	}
            		echo '</tr>';
            }
        ?>
    </table>
</body>
</html>
To capture visitor information:
Code:
<?php

$dbHost = "localhost";
$dbName= "rptDatabase";
$dbUsername = "username";
$dbPassword = "password";
$ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$host = $_SERVER['HTTP_HOST'];
$page = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
$date = date("Y/m/d");
$time = date("H:i:s", strtotime("+19 hours"));

	mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
	$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

	$stmt = $conn->prepare("INSERT INTO tblTraffic (ip, host, page, date, time) 
						  	VALUES (?, ?, ?, ?, ?)");
	$stmt->bind_param("sssss", $ip, $host, $page, $date, $time);
	$stmt->execute();
	$stmt->close();
	$conn->close();

?>
Attached Images
File Type: jpg output.jpg (92.0 KB, 8 views)
vba_php is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Apps vs. scripting the_net_2.0 Other Software 1 08-26-2016 09:15 AM
Spiders Brianwarnock The Watercooler 11 01-30-2013 08:18 AM
Scripting something to control other programs buratti General 3 10-01-2010 08:27 AM
Report vba scripting Espinoza84 Modules & VBA 5 05-30-2008 07:37 PM
Scripting.Dictionary bauer Modules & VBA 4 02-05-2003 07:38 AM




All times are GMT -8. The time now is 01:19 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World