Check Whether Javascript is Enabled on Browser Using php
- Article
- Comment
You can check js enable using php also. From my previous article shows to check it using HTML5. Here I am giving you two ways to check it using php. Php is server side script, eventhough we can identify the client browser capability and work based on it. First option is very simple code to perform it.
<script type="text/javascript"> document.cookie = 'kvhasJS=true'; </script> <?php // Kvcodes, js testing if (isset($_COOKIE['kvhasJS'])){ // normal page render }else{ header('Location: https://kvcodes.com/index-nojs.php'); } ?>
The above code will help you to identify the client browser. The second method is also simple, here is code
<? if($_SESSION['JSexe']){ //3rd check js if($_COOKIE['JS']) setcookie('JS','JS',time()-1);//check on every page load else header('Location: js.html'); } //2nd so far it's been server-side scripting. Client-side scripting must be executed once to set second cookie. //Without JSexe, user with cookies and js enabled would be sent to js.html the first page load. elseif($_COOKIE['PHP']) $_SESSION['JSexe'] = true; else{ //1st check cookies if($_GET['cookie']) header('Location: cookies.html'); else{ setcookie('PHP','PHP'); header('Location: '.$_SERVER['REQUEST_URI'].'?cookie=1'); } } ?>
Any bugs and doubts, drop your comment below.