如何计算有多少访问者启用了js,有多少没有? [英] How to count how many visitor's have js enabled and how many does not?

查看:100
本文介绍了如何计算有多少访问者启用了js,有多少没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我网站上有多少访问者启用了js
以及关闭了多少人。


我没有'找不到搜索Google群组的简单解决方案所以我建议使用php和mysql以下

在mysql中用两个字段nonjs创建一个表mc_jscount表(int)

和js(int)。创建一条nonjs和js设置为零的记录。


将此代码放在页面顶部:


<?php

//将nonjs增加1

$ sql =''update mc_jscount set nonjs = nonjs + 1'';

$ result = mysql_query( $ sql);

if(mysql_affected_rows()== -1){echo''

查询中出现意外错误:< br />''; die($ sql);}


//检查我们是否自己再次调用此页面,如果我们

请设置$ p_count

if(isset($ p_count))

{

$ sql =''update mc_jscount set nonjs = nonjs - 2,js = js + 1'';

$ result = mysql_query($ sql);

if(mysql_affected_rows()== -1){echo''

查询:< br />'';死($ sql);}

}

其他

//写下面的javascript:

echo' '< script language =" JavaScript">

location.href =" mc_default.php?count = 1";

< / script>'' ;

?>


页面的nonjs访问者将nonjs字段增加1并且

因为他没有js启用脚本php写入将无法运行。


当js访问者进入页面时,nonjs会增加1,

然后因为这是第一次调用页面$ p_count没有设置,所以

javascript将被写入并执行。当它执行时,

返回页面,因此nonjs再次增加1。然而现在nonjs

减少了2并且js增加了1,这照顾了早先增加的两个
nonjs。这次脚本没有写好,所以他可以继续享受页面。


如果这不起作用,根据我的测试,它确实如此或者是很长的

简单的做法,请发表评论。


谢谢!


此致,


Jan Nordgreen

解决方案

sql =''update mc_jscount set nonjs = nonjs + 1'';


result = mysql_query(


sql);

if(mysql_affected_rows ()== -1){echo''

查询中出现意外错误:< br />'';死亡(

I would like to know how many of the visitors to my site has js enabled
and how many has it turned off.

I haven''t found a simple solution searching Google groups so I suggest
the following using php and mysql:

Create a table mc_jscount table in mysql with two fields nonjs (int)
and js (int). Create one record with nonjs and js set to zero.

Put this code at the top of your page:

<?php
// increase nonjs by 1
$sql = ''update mc_jscount set nonjs = nonjs + 1'';
$result = mysql_query($sql);
if (mysql_affected_rows() == -1) {echo ''Unexpected error in the
query:<br/>''; die($sql);}

// check if we are calling this page again ourselves, see below, if we
do $p_count is set
if (isset($p_count))
{
$sql = ''update mc_jscount set nonjs = nonjs - 2, js = js + 1'';
$result = mysql_query($sql);
if (mysql_affected_rows() == -1) {echo ''Unexpected error in the
query:<br/>''; die($sql);}
}
else
// write the javascript below:
echo ''<script language = "JavaScript">
location.href = "mc_default.php?count=1";
</script>'';
?>

A nonjs visitor to the page will increase the nonjs field by 1 and
since he has not js enabled the script php writes will not run.

A js visitor will have nonjs increased by 1 when he enters the page,
then since this is the first call to the page $p_count is not set so
the javascript will be written and executed. When it executes he
returns to the page so nonjs is increased by 1 again. However now nonjs
is reduced by 2 and js is increased by 1, which takes care of the two
nonjs increases earlier. This time the script is not written so he can
go on and enjoy the page.

If this does not work, according to my testing it does, or is a long
winded way of doing something simple, please post a comment.

Thanks!

Regards,

Jan Nordgreen

解决方案

sql = ''update mc_jscount set nonjs = nonjs + 1'';


result = mysql_query(


sql);
if (mysql_affected_rows() == -1) {echo ''Unexpected error in the
query:<br/>''; die(


这篇关于如何计算有多少访问者启用了js,有多少没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆