Question

Okay, I have created a new question to clarify my old one, which is available here: Check if certain text was outputted to the screen PHP Currently I have this code:

<?php
echo "

<noscript><h2>! JavaScript is not enabled!!! Features will not work !</h2></noscript>

<script type=\"text/javascript\">
    document.cookie= \"jsEnabled=true\";
</script>
";

if (isset($_COOKIE['jsEnabled'])) {
    // Javascript is enabled!
}
 else {
     die("JavaScript is not enabled!");
 }

?>

I am not sure why this wont work! It should kill the PHP if JS is disabled! Thanks!

Was it helpful?

Solution

JavaScript processes after PHP has fully given out the page, not before, and not in symbiosis. As such, your PHP call will only work for the second call to the page, not the first.

That is, if you accept cookies in the first place.

If you want to prevent users without JS from using the interface on a page, consider generating the interface in pure JS instead. More reliable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top