Javascript, Web Development

PHP Detect Whether User has JavaScript (JS) enabled

Author Note: To the people who wanna seem elite or 1337:- JavaScript checks are real and do need to be done in certain situations so before you say that javascript checks are noob take a look in the mirror and you’ll see noob.

Edit: after I made this post I saw this I have had my own theory of making a AJAX poll if the user has javascript otherwise the user don’t.

Now I recently came over a design flaw when building a JQuery IM for my site. I relised (just like facebook) I need a way to stop those without javascript from appearing online to people with javascript. This is since those with javascript can use the IM and those without can not.

I had my own idea of surrounding a html form with PHP variables and using Javascript to submit that form. Whether or not this form subbmitted would tell if the user has JavaScript or not. I tried to find a better version or method from the Internet but this was the best I found (taken from bluejon):

//Needs html tags to work !!
//Needs html tags to work !!
<a  href=""/>MENU</a>
$_SESSION['js']= array_key_exists('js', $_POST) ? $_POST['js'] : '';
if (empty($_SESSION['js'])){
    <form name="postJs" action="<?php echo $PHP_SELF ?>" method="post">
    <input type="hidden" name="js" value="on">
    <script type="text/javascript">

if ($_SESSION['js']== "on"){
  print"<h3>Javascript is ON</h3><br>";
  print"Php code can be added here!<br>";
  print"<h3>Javascript is OFF</h3><br>";
  print"Php code can be added here!<br><br><br>";

<a  href="">Display php source code </a>

However there are problems to this I am currently working on a better version that wont redirect the page twice.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s