D
damezumari
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
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