[FONT="Verdana"]Hi,
At the bottom of this post is a script I am using to log visitor information.
I've tried to implement a visitor screen resolution line of input, but I have it written incorrectly. The object is; I simply want to include the visitors screen resolution as part of the record.
This is how it currently prints to file:
*****************************************
IP Address: 65.55.165.69
new user: Yes
Browser name: MSIE 7.0
Operating System: Windows NT 5.2
Resolution: + screen.width +'x'+ screen.height
Language: English
Date/Time: Tuesday January 29 2008 - 4:04:00 AM
Last Visit: Tuesday January 29 2008 - 4:04:00 AM
Days since last visit: 0
Referrer page: http://search.live.com/results.aspx?q=design
Keywords used to search your site:
*****************************************
The line I would like to rint correctly is; Resolution.
I added the following to capture visitor screen resolution:
//Get resolution
$resolution="+ screen.width +'x'+ screen.height";
and
$newrecord="IP Address: $ipaddress\r\nnew user: $newuser\r\nBrowser name: $browser\r\nOperating System: $operatingsystem\r\nResolution: $resolution\r\nLanguage: $thelanguage\r\nDate/Time: $thedate\r\nLast Visit: $visit\r\nDays since last visit: $visitdays\r\nReferrer page: $referrerpage\r\nKeywords used to search your site: $keywords\r\n********************************************\r\n";
Except, it prints like this:
Resolution: + screen.width +'x'+ screen.height
How can this be fixed and is there anything that could be added to the script to capture further information that isn't already included in the script?
I think it's a nice and simple script and like using it.
Any help on this is much appreciated!
Thank you!
Script:
=======================================
function getkeywords($thereferrer){
$searchengines=Array("search.yahoo p", "google q", "altavista q", "alltheweb q", "search.msn q");
for($i=0;$i<count($searchengines);$i++){
$currsearch=split(" ", $searchengines[$i]);
if(strpos($thereferrer, $currsearch[0])!=false){
$searchqueries=split("&", split("?", $thereferrer[1]));
break;
}
}
if($searchqueries){
for($i=0;$i<count($searchqueries);$i++){
if($searchqueries[$i][0]==$currsearch[1]){
$thekeywords=join(", ", split(" ", urldecode($searchqueries[$i][1])));
break;
}
}
}
return $thekeywords;
}
//This function returns the language based on the accept language variable
function getlanguage($lan){
$languages=Array("German de", "Chinese zh", "Spanish es", "French fr", "Japanese ja", "Italian it", "English en");
for($i=0;$i<count($languages);$i++){
$currlan=split("-", $lan);
$languagedb=split(" ", $languages[$i]);
if($currlan[0]==$languagedb[1]){
$thelanguage=$languagedb[0];
break;
}
}
if(!$thelanguage) $thelanguage="Other ($lan)";
return $thelanguage;
}
//Get IP address
if (getenv("HTTP_X_FORWARDED_FOR"))
{
$ipaddress=getenv("HTTP_X_FORWARDED_FOR");
}
else
if (getenv("HTTP_CLIENT_IP"))
{
$ipaddress=getenv("HTTP_CLIENT_IP");
}
else
{
$ipaddress=getenv("REMOTE_ADDR");
}
//$ipaddress=getenv("LOCAL_ADDR");
//Get browser agent info
$agent=split("; ", getenv("HTTP_USER_AGENT"));
//Get browser name
$browser=$agent[1];
//Get operating system
$operatingsystem=$agent[2];
//Get resolution
$resolution="+ screen.width +'x'+ screen.height";
//Get browser language
$thelanguage=getlanguage(getenv("HTTP_ACCEPT_LANGUAGE"));
//Get date and time
$thedate=date("l")." ".date("F")." ".date("j")." ".date("Y")." - ".date("g").":".date("i").":".date("s")." ".date("A");
//Get referrer page from a parameter passed by the visits.js Javascript file
$referrerpage=$r;
//Get the keywords used to search the page
if($referrerpage!="") $keywords=getkeywords($referrerpage);
else $keywords="Not Available";
//Check if referrer is blank
if($referrerpage=="") $referrerpage="Not Available";
//Determine if user is new to the website
$newuser=($visit1=="")?"Yes":"No";
//Get date and time of last visit
$visit=($visit1)?$visit1:$thedate;
//Get number of days since last visit
$visitdays=($visit2!="")?intval((time()-intval($visit2))/(606024)):0;
//If result is a decimal number, then set it to 0
if($visitdays<1) $visitdays=0;
//Set cookie expire time in (30 days 24 hours 3600 seconds per hour)
$cookie_expire=time()+(30243600);
//Set last visit date and time in cookie
setcookie("visit1", $thedate, $cookie_expire);
//Set current timestamp in cookie
setcookie("visit2", time(), $cookie_expire);
//Open the text file to log the new visit
$visitlog=fopen("visits.txt", "a");
//Create the new record that will contain IP address, is user new to site, browser and operating system, browser language, date and time, last visit, number of days since last visit, referrer page, and keywords used by user to search your website
$newrecord="IP Address: $ipaddress\r\nnew user: $newuser\r\nBrowser name: $browser\r\nOperating System: $operatingsystem\r\nResolution: $resolution\r\nLanguage: $thelanguage\r\nDate/Time: $thedate\r\nLast Visit: $visit\r\nDays since last visit: $visitdays\r\nReferrer page: $referrerpage\r\nKeywords used to search your site: $keywords\r\n********************************************\r\n";
//Save the new record in the file
fputs($visitlog, $newrecord);
//Close the file
fclose($visitlog);[/FONT]