سؤال

How would I check if certain text was outputted to the screen using PHP?
For example, I have this code:

<html>
<body>
<noscript>
error: no js
<noscript>
<?php
//detect if the HTML printed out "error: no js"
?>
</body>
</html>

I want to detect if HTML printed out the specified <noscript> message. Is this possible to do with PHP, or on a PHP page? Is there a better way to stop any scripts if JavaScript is disabled, or if certain output was outputted?

I would especially like to do this because then I can pass certain output if certain conditions were met, and have the PHP act according to the output.
Thanks!

هل كانت مفيدة؟

المحلول

The only thing I can think of is setting a cookie:

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

Then, you can do a simple check in PHP:

<?php

if (isset($_COOKIE['jsEnabled'])) {
    // Javascript is enabled!
} else {
    // Javascript is not enabled!
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top