如何使用PHP检查某些文本是否输出到屏幕?
例如,我有以下代码:
<html>
<body>
<noscript>
error: no js
<noscript>
<?php
//detect if the HTML printed out "error: no js"
?>
</body>
</html>
我想检测HTML是否打印出指定的<noscript>
消息。这可能与PHP或PHP页面有关吗?如果禁用JavaScript,或者输出了某些输出,是否有更好的方法可以停止任何脚本?
我特别喜欢这样做,因为如果满足某些条件,我可以传递某些输出,并根据输出让PHP行事。
谢谢!
答案 0 :(得分:3)
我唯一能想到的就是设置一个cookie:
<script type="text/javascript">
document.cookie = "jsEnabled=true";
</script>
然后,您可以在PHP中进行简单的检查:
<?php
if (isset($_COOKIE['jsEnabled'])) {
// Javascript is enabled!
} else {
// Javascript is not enabled!
}