Check if JS is enabled

People have such a problem. Execute one function if javascript is enabled in the browser and execute another if disabled. How to implement using PHP? There is a terribly stupid idea – to create a variable in JS, then pass it to php. Then check if this variable is empty using php. Accordingly, if JS is disabled, then the variable will be empty, because the script will not transfer anything, and if it does, it will be with the data. So you can calculate if JS is enabled or not? Who can help write such a function?

Answer 1, authority 100%

$_SESSION['JS_ON'] = (!empty($_SESSION['JS_ON']) || !empty($_GET['js'])); // JS_ON  == true,           get-
if (!$_SESSION['JS_ON'] && empty($_SESSION['JS_CHECKED'])) {
  echo '<script type="text/javascript">top.location.href="?js=1";</script>';
  } //    ,  

Thus. on the first visit to the site, a person who has JS enabled will be redirected (1 time) and you will have a variable $_SESSION['JS_ON']– accordingly, whether javascript is enabled or not.

Answer 2, authority 20%

$browser = get_browser();
//  $browser   
$browser = (array) $browser;
if ($browser["javascript"] == 1) :
print "Javascript enabled!";
else :
print "No javascript allowed!";

Answer 3, authority 20%

The get_browser()function reports the capabilities of the user’s browser, that is, if the browser works with jsthen $browser["javascript"]always will be equal to 1, but this does not mean that javascriptis not disabled by the user in the browser settings.