有没有办法检查JavaScript是否启用了PHP?如果是这样的话,是怎么做的?
发布于 2013-03-21 09:04:35
这是我在我的页面上创建的一个小include,用来检测是否启用了js。希望这能帮上忙。
<?php
//Check if we should check for js
if ((!isset($_GET['jsEnabled']) || $_GET['jsEnabled'] == 'true') && !isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
   //Check to see if we already found js enabled
   if (!isset($_SESSION['javaEnabled'])){
      //Check if we were redirected by javascript
      if (isset($_GET['jsEnabled'])){
         //Check if we have started a session
         if(session_id() == '') {
            session_start();
         }
         //Set session variable that we have js enabled
         $_SESSION['javaEnabled'] = true;
      }
      else{
         $reqUrl = $_SERVER['REQUEST_URI'];
         $paramConnector = (strpos($reqUrl, "?"))? "&" : "?";
         echo "
            <script type='text/javascript'>
               window.location = '" . $reqUrl . $paramConnector . "jsEnabled=true'
            </script>
            <noscript>
               <!-- Redirect to page and tell us that JS is not enabled -->
               <meta HTTP-EQUIV='REFRESH' content='0; " . $reqUrl . $paramConnector . "jsEnabled=false'>
            </noscript>
         ";
         //Break out and try again to check js
         exit;
      }
   }
}
?>https://stackoverflow.com/questions/4454551
复制相似问题