Forum Moderators: coopster

Message Too Old, No Replies

Site User Information

For hit counter

         

NancyJ

1:10 am on Dec 10, 2004 (gmt 0)

10+ Year Member



Can anyone point me in the direction of a list of all the information I can get about a visiter to my website with PHP, like referer, browser, screen resolution - stuff like that.
I have a javascript stat tracker on my website and theres nothing really wrong with it in fact its really rather good but it occurred to me that I could write my own and obviously that would be better ;) plus I'd like the mental exercise, I just need to know where to look.
I dont even know what search terms to try to find out this kind of info so I hope you can help :)

lZakl

2:18 am on Dec 10, 2004 (gmt 0)

10+ Year Member



Ad far as asking for host, and host resolution....

$REMOTE_ADDR; Will return the value of the host IP address.

$domain = GetHostByName($REMOTE_ADDR); Will resolve the host, if there is one.

As far as PHP reading a client machine for variables such as Screen resolution, as far as I know it can't. But it CAN read JavaScript input, which in turn would feed the PHP script with the info it needs.

After a quick search at 'php dot net' it returned the following info:


5. How can I pass a variable from Javascript to PHP?

Since Javascript is (usually) a client-side technology, and PHP is (usually) a server-side technology, and since HTTP is a "stateless" protocol, the two languages cannot directly share variables.

It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this -- it allows PHP code to capture screen height and width, something that is normally only possible on the client side.

<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
// output the geometry variables
echo "Screen width is: ". $_GET['width'] ."<br />\n";
echo "Screen height is: ". $_GET['height'] ."<br />\n";
} else {
// pass the geometry variables
// (preserve the original query string
// -- post variables will need to handled differently)

echo "<script language='javascript'>\n";
echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
. "&width=\" + screen.width + \"&height=\" + screen.height;\n";
echo "</script>\n";
exit();
}
?>

lZakl

2:26 am on Dec 10, 2004 (gmt 0)

10+ Year Member



I'm sorry I should have read the whole thing before replying...

This should give you the refering address also

echo "Referer: " . $_SERVER["HTTP_REFERER"] . "<br/>";

and this Browser

echo "Browser: " . $HTTP_USER_AGENT . "<br />";