Check if certain text was outputted to the screen PHP

僤鯓⒐⒋嵵緔 提交于 2019-12-11 11:38:54

问题


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!


回答1:


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!
}


来源:https://stackoverflow.com/questions/16742307/check-if-certain-text-was-outputted-to-the-screen-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!