Google Hits

Started on the old forum in November 2013 · view the original in the archive · old links redirect here

4 replies · 785 views · started 13 years ago · 1 min read

3 participants
pmbguy Senior · 344 posts #1

Ok, well I was bored yesterday n wanted to code a little hit counter for my site that logs hits by matching ip, browser, n platform since there's no login... anyways, a few minutes later, i noticed Googlebot popping up, n was curious as to what pages google was visiting, so added a few lines of code to single out googlebot n log which urls it was loading...

thought it might be useful for some people... then you can see where you might need to block robots, etc...

ok, there's a readme included, lol all three lines of it, but here's the basics... Step 1. Input DB info in dbconnect.php Step 2. Upload To Server in a subdirectory or whereever it will be most convenient for you... Step 3. Include it in your index.php either after database connection with out using dbconnect, although obviously you will need to create tables, etc... Or just use it in standalone mode running with the dbconnect file in which case you can even use a separate database for logging hits...

Will update it a bit n upload improved version a bit later...

Hope it helps someone, n enjoy optimising your site for google...

Attachments: google_hits.zip
pmbguy Senior · 344 posts #2

ok, updated to make it an image counter as basic a counter as it is, lol and also for anyone who is using include method, updated to log page hits by unique browser, ip n platform matches, sorry the filesize suddenly shot up, had to incude a font in zip file...

ok, i didn't really need to include it, but just makes things a bit more foolproof...

Demo: External image (may be gone)

oh n you need to include if you want it to log urls loaded, will be trying to figure out a way around that... ok, on line 11... change:

$pageurl = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);

for

$pageurl = htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_QUOTES);

and you will log which page counter loads from as image...

Attachments: google_hits_alpha.zip
something else Fellow · 2,296 posts #3

pmbguy wrote: ok, on line 11... change:

$pageurl = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);

for

$pageurl = htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_QUOTES);

referer can be easily spoofed which makes the script vulnerable to sql injection :/

pmbguy Senior · 344 posts #4

something else wrote: referer can be easily spoofed which makes the script vulnerable to sql injection :/

i know, one reason the script runs on separate database with different user n password from main database, lol... n i forgot to sanitise in what i posted here, but thanks for the reminder... Sanitise your urls...

function cleanurl($url) {
	$bad_entities = array("&", "\"", "'", '\"', "\'", "<", ">", "(", ")", "*");
	$safe_entities = array("&", "", "", "", "", "", "", "", "", "");
	$url = str_replace($bad_entities, $safe_entities, $url);
	return $url;
}

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close