PHP beginner |
|
Euhmmm...
Probleem een is simpel, los het op met ajax:
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
param="width="+screen.width+"&height="+screen.height;
req.open("post", "log.php");
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", param.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function(){}
req.send(param);
if(window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if(window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } param="width="+screen.width+"&height="+screen.height; req.open("post", "log.php"); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", param.length); req.setRequestHeader("Connection", "close"); req.onreadystatechange = function(){} req.send(param);
Probleem 2: sommige mensen hebben geen js (bots, oude browsers, rare beveiligingssoftware, etc...). Als je ook de user-agent, ip-adressen en datum/tijd tegelijk opslaat heb je meer info.
Maak de juiste database, en doe dit.
Log.php:
<?php
is_numeric($_POST['width']) or die("width is not numeric");
is_numeric($_POST['height']) or die("height is not numeric");
mysql_connect("server","database","wachtwoord") or die("MySQL ".mysql_errno().": ".mysql_error());
mysql_select_db("licht") or die("MySQL ".mysql_errno().": ".mysql_error());
mysql_query("INSERT INTO log VALUES ('".$_SERVER["REMOTE_ADDR"]."',CURRENT_TIMESTAMP,'".$_SERVER["HTTP_USER_AGENT"]."','".$_POST['width']."','".$_POST['height']."');") or die("MySQL ".mysql_errno().": ".mysql_error());
mysql_affected_rows() or die("MySQL ".mysql_errno().": ".mysql_error());
?>
<?php mysql_query("INSERT INTO log VALUES ('".$_SERVER["REMOTE_ADDR"]."',CURRENT_TIMESTAMP,'".$_SERVER["HTTP_USER_AGENT"]."','".$_POST['width']."','".$_POST['height']."');") or die("MySQL ".mysql_errno().": ".mysql_error()); ?>
Deze code haal ik bijna rechtstreeks hieruit. |