如何计算有多少访问者启用了js,有多少没有?

编程入门 行业动态 更新时间:2024-10-15 04:20:56
本文介绍了如何计算有多少访问者启用了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,有多少没有?

本文发布于:2023-11-30 03:46:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有多少   访问者   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!