How to detect if JavaScript is disabled in Php

by Dinesh 2014-12-26 18:34:16

You can easily detect wheather the JavaScript is enable or disable by using following code.
<?php

if(!isset($_SESSION['js'])||$_SESSION['js']==""){
  echo "<noscript><meta http-equiv='refresh' content='0;url=/get-javascript-status.php&js=0'> </noscript>";
   $js = true;

 }elseif(isset($_SESSION['js'])&& $_SESSION['js']=="0"){
   $js = false;
   $_SESSION['js']="";

 }elseif(isset($_SESSION['js'])&& $_SESSION['js']=="1"){
   $js = true;
   $_SESSION['js']="";
}

if ($js) {
    echo 'Javascript is enabled';
 } else {
    echo 'Javascript is disabled';
}

?>
And then inside get-javascript-status.php :
$_SESSION['js'] = isset($_GET['js'])&&$_GET['js']=="0" ? "0":"1";
header('location: /');

Tagged in:

1851
like
0
dislike
0
mail
flag

You must LOGIN to add comments