开发者

Get URL of calling webpage in PHP

开发者 https://www.devze.com 2023-01-11 07:54 出处:网络
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 webs

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 w开发者_如何学运维hich 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!


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消