I found it.
The error were caused by a configuration in the php.ini
output_buffering should be on instead of off otherwise the cookie isn't set.
It's impossible to call a PHP function directly from javascript but there is a nice workaround for this.
Here is the code to fix it (this one works with vbulletin, if you build one with an image it doesn't work).
Code:
<script language="Javascript">
var myUrl="./function.php?sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+document.referrer+"&page="+location.href;
var iframe1=document.createElement("iframe");
iframe1.src=myUrl;
document.body.appendChild(iframe1);
iframe1.removeNode(true); //hides the frame from the user
</script>
Enjoy