...

View Full Version : Stats Tracking With Image



pixencom
05-15-2008, 01:59 AM
I am trying to track page load using an image. So basically I put the code <img src="image.php"> I want the code in image.php to insert into a database what page the code <img src="image.php"> is in.


$_SERVER["REQUEST_URI"];

Does not work as it shows image.php. How do I get the page URL? Any help would be great. Thanks.

Fou-Lu
05-15-2008, 02:04 AM
Have you tried the $_SERVER['HTTP_REFERER']? That may be the one your looking for.
I don't recommend actually tracking this, as it will be hell on your database. Instead, if its a hotlinking issue, I'd just deny anyone who is outside of my site to link the image. Of course, they can always just save your image, but at least they are not using your bandwidth anymore.

Oh, I should mention as well, this is not an overly reliable method, referer (yes it is spelled wrong I don't know why they did that >.<) can be changed by client. But at least it will dissuade most users :)

pixencom
05-15-2008, 02:07 AM
Its not for hotlinking. I want to track how many users come on a particular page. So in the database I have an entry for each page. When a user visits a page, another hit gets added to the entry corresponding to the page.

Fou-Lu
05-15-2008, 02:11 AM
Yep, ok then that should do it as long as the referer is being sent along. I may suggest that you use some php logic to first determine if a record exists for a specific site (or page if you really wanted it, but I'd just do the site), and a counter variable that you can increment. Use a long for this.

Good luck mate!

pixencom
05-15-2008, 02:14 AM
Referrer is the only way it will work?

Fou-Lu
05-15-2008, 02:18 AM
Hmm, best I can think of off the top of my head in PHP anyway. I'll look around as well to see if I can find a better solution, but I've never actually done a tracker between multiple locations before - only the hotlink prevention.

There is probably a more advanced solution (curl or something of the sorts), but I'm not sure how it would be put together. Perhaps someone else on the site has already built a similar service before, and could let you know of another way.

pixencom
05-15-2008, 02:49 AM
http://www.statcounter.com/ is implementing exactly what I would like to code. If anyone is confused at what I want, visit their site.

logictrap
05-15-2008, 07:41 AM
Here's one method that should work - this assumes your page is a php file:

1) Set up a MYSQL database with at least two fields: (id & page name) make id an auto increment field and page name a varchar(255).
2) Create a variable on each page to store it's page name (ie $page='photos.php';).
3) Use php to insert the page name ($page) into the database on each visit.
4) To view the page count use a mysql statement to return the count for each page name.

pixencom
05-15-2008, 09:00 AM
Here's one method that should work - this assumes your page is a php file:

1) Set up a MYSQL database with at least two fields: (id & page name) make id an auto increment field and page name a varchar(255).
2) Create a variable on each page to store it's page name (ie $page='photos.php';).
3) Use php to insert the page name ($page) into the database on each visit.
4) To view the page count use a mysql statement to return the count for each page name.

Thank you for your reply. This is what I have now:

1) I have the DB setup
2) On every page I have included a PHP file
3) The PHP file updates the information to the Database

What I want is instead of including this PHP file, I want it to be an image that I can put into <img src="log.php">. When I do that, I loose the page information. Right now I am getting the page with REQUEST_URI, but that doesnt work when log.php is called upon as an image.

pixencom
05-15-2008, 09:25 AM
UPDATE:

Just wanted to confirm that HTTP_REFERER gets the job done but that wont work for people with sending referrer info off. Any ideas?

logictrap
05-15-2008, 03:39 PM
you might be loosing the referrer value because you are calling the log.php from another page - so the referrer is the page calling log.php not the original referrer.

Try using a session value to store the referrer value and the use the session value in the log.php to retrieve it.

Main Page:

<?php
session_start();
$_SESSION['referrer']=$_SERVER['HTTP_REFERER'];
?>
log.php


<?php
session_start();
// MySQL insert statement - insert $_SESSION['referrer'] into some table
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum