tags:

views:

42

answers:

2

Hello all,

I am working on a website statistics engine for a class. The idea being that you can simply embed a little code in your web page which will call the stats website on every page load and the stats website will then track your hits and such… nothing ground breaking.

What I would like to do is be able to break down website hits by webpage. For instance, a person can include the same code on each page, and the stats website will know which page got hit how many times. Is there a way in PHP to obtain the URL of the calling page (the page on which the embedded code exists)? I know how to get the URL of the page in which the PHP code is running, but not the calling page.

Alternatively, I could probably use some JavaScript to pass the page URL to the stats website, but the less code that needs to be embedded the better so I’m hoping for a PHP solution.

Thanks in advance for any and all help!

+2  A: 

$_SERVER['HTTP_REFERER'] will get you the referring page.

Ian Wetherbee
Yes I've heard of this... and I probably should have tried it before posting this question. I didn't think an image or embedded script would have a referrer. Ill give it a shot. Thanks!
Nate
Worked! Thanks!
Nate
A: 

In addition to $_SERVER['HTTP_REFERER'] since there may be large chunks of the URI you wish to ignore, you can just pass the page name as a request param to the called script.

I.E. on the page with stats tracking you request

URL/stats_tracker.php?page=checkout

on the stats tracker page you just look for

$_REQUEST['page'];

This can be cleaner than looking at the whole URL.

Zak