php中使用js得到的值,无法进行比较吗?$width.="<script>";    
$width.="document.write(window.screen.width);";      
$width.="</script>";  
$isMobile = ($width > 600)?'0':'1';
echo $isMobile;isMobile的值会一直是1,如果int($width)强转,那么int($width)的值会是0。

解决方案 »

  1.   

    这么得不出来吧 你输出来$width 看看 
      

  2.   

    js是在访问者的浏览器运行的,php是服务器上运行的,是两台机器,相互取值就必须有一个传送过程
    就算在本机测试,也是“模拟”,过程仍然是按两台机器
      

  3.   

    你这写肯定不行。。
    你这就包括width= 整段你输的文本了
      

  4.   

    至少需要这样写if(isset($_GET['screen_width'])) echo $_GET['screen_width'];
    else echo "<script>location.replace('?screen_width=' + window.screen.width)</script>";