So looking around some more, to minimize server load with file read/write I would have to do this (just do it one time once the user tries to leave the page:
window.onbeforeunload = function () {
var checkboxImg = new Image();
checkboxImg.src = "checkbox.php?reviews-chk-longer="+ reviews-chk-longer.checked +
"&reviews-chk-discrete=" + reviews-chk-discrete.checked +
"&"...The rest of the checkboxes...;
}
I know that window.onbeforeunload doesn't work in some rare instances, but as I said earlier these figures don't need to be 100% perfect, I'd be happy with 50% executions :)
Now in my PHP file I can pull a clients IP address with:
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Open my file with $data = file_get_contents($file);
or should I make it easier on myself and just use:
$checkboxes = file('checkbox.log');
(The above file won't be in binary format though...but maybe it is better to go simple sometimes.)
then
1) check to make sure that none of the array elements contain the IP of the current user
2) make sure that there are other checkmarks other than just the 1st 2
3) just add the values that were passed to this php file via the javascript to our array (an unchecked checkbox returns 0, yay!) using:
$reviews-chk-longer=$_GET['reviews-chk-longer'];
4) add the IP address of the current user to a new array element
5) write our array to the file (would it be easier to convert the array into a string then just use $f=file_put_contents($file, $content);?)
And that's it? Am I missing anything?